-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to return inline style even if we want to avoid it at the beginning #5933
Add an option to return inline style even if we want to avoid it at the beginning #5933
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes all sense, I'd like to stay away from inline styles in general but this is actually a nice fix for the inline
option.
Thank you also for the effort of making a good PR (context of the issue, comments in the right place, tests, etc.) 👏
@@ -5,7 +5,7 @@ interface NOOP {} | |||
|
|||
export type Debounced = Function & { cancel(): void }; | |||
|
|||
export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean }; | |||
export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean; inline?: boolean }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one could be moved to UpdateStyleOptions
type (I'll do it)
/** | ||
* Configurations for keymaps | ||
*/ | ||
keymaps?: KeymapsConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇♂️
test('set style on id and inline style', () => { | ||
obj.setStyle({ color: 'red' }); // Should be set on id | ||
obj.setStyle({ display: 'flex' }, { inline: true }); // Should be set as inline | ||
|
||
expect(obj.getStyle()).toEqual({ | ||
color: 'red', | ||
}); | ||
expect(obj.getStyle({ inline: true })).toEqual({ | ||
display: 'flex', | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Hi 👋
Here is the context why I'm creating this PR. I saw that the config parameter
avoidInlineStyle
is now deprecated because of responsive and state management. But in some case we could still need inline style.For example, if you get a dynamic list with multiple elements and each element has a specific color that you want to use as text color. You can only do it with inline style. But if here we set inline style, this is because you want it and you know you will cannot handle responsive and state on the text color.
avoidInlineStyle = true
If I understand correctly,
avoidInlineStyle
is set to true by default to handle responsive and state management. We can still add inline style withsetStyle('color: red;', { inline: true })
but when we get the final HTML withtoHTML()
, the inline style is remove and style is lost.avoidInlineStyle = false
When we put
avoidInlineStyle
to false, and we dosetStyle('color: red;', { inline: true })
, the inline style is set correctly but at the CSS generation (editor.getCss()
), the same style is also added in the CSS code. What we don't want because we explicitly specify{ inline: true }
when setting the style.What do I change?
So I just add one export parameter in
ToHTMLOptions
namedkeepInlineStyle
to allow inline style when it is explicitly wanted.By doing that, I saw that the test suite
Component
was running an editor withavoidInlineStyle
set to false, which is not the default way of working now if I understand. So I set it to true in the test suite and fix 3 tests that work a little but differently.To conclude
I hope my PR is clear and you will understand why I did this.
PS: Something totally different, I add the
keymaps
config key in the editor config type to avoid typescript check issue when using it.Do not hesitate if you have any reviews or comments!