-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Feature suggestion] optionally insert styles from StyleManager with !important #1041
Comments
Yeah, there should be a way to solve this. But I have to say that using I would rather do something like Could I know what kind of pre-compiler you're using? Looks really wired... |
@chapterjason I am not in control over the template. So I wouldn't know how to answer that question. Grapes should work with any HTML and CSS, so I don't think it's relevant. I would not want to remove !important statements from templates, because doing so can affect the render. If they have multiple statements, some with important and some without, and in a certain order, you want it to render exactly as it was intended to. Removing important statements would change this. |
It might be a good idea, but what about improving those events (eg. pass |
@artf do you mean that we'd have to then write plugins to listen to those events and add additional styling to the component? This seems complicated as it depends on if the styling is inline or through classes. Since the core of grapes is editing and styling components, I'd argue that this feature suits well in core. There is already an important flag anyway, it just doesn't work as one would expect :) |
@tommedema Components and CssRules implement Styleable, therefore you would get it in all case.
Not additional, you overwrite the style triggered on that model, eg. // eg. your configs
const styleImportant = 1;
// ...
editor.on('styleable:change', (model, property) => {
const value = model.getStyle()[property];
console.log('Styled ', property, value);
if (styleImportant) {
model.addStyle({ [property]: value + ` !important` });
}
}); |
added PR at #1056 |
@artf so now that I am using this in production it turns out that there is an issue with the style manager's color picker when styles have !important: (e50000 is red but it's shown as white here) The color picker becomes buggy in several ways, probably because it cannot parse the color anymore after
The |
To be honest, I'd expect such a check on all inputs 🤔 Do have such an issue only with color inputs? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'd like to suggest a feature that can be enabled through config:
styleAsImportant: true
(defaults to false, i.e. non-breaking). I thought this was already possible by configuring the cssComposer, though I've now learned that this is not the case (see below for an explanation).I am working with templates that sometimes were generated from pre-compilers that excessively use the !important flag. For example a button in a template might be styled as:
As a result, styling this button with Grapes has absolutely no effect. The most obvious way to make it work with grapes, is to ensure that:
!important
(this feature)I guessed that the proper way would be to make CssRule.js#36 configureable. I tried to set this
important
flag using:But this does not seem to have an effect. Moreover, when I hardcode it to
true
in the code, I see that there are two issues with this implementation:!important
to rules that come from the template. This feature suggestion is specifically for rules that are manually added through the style manager, because these should overwrite the template's styles. Otherwise there is no added value.!important
twice if there is already an important statement in rules from the template, causing the rendering to fail due to having invalid css properties:Therefore my suggestion is to create a new config value
styleAsImportant: true
(defaults to false, i.e. non-breaking). After some initial debugging I found that this change makes this happen:style_manager/index.js line 283:
from:
to:
This seems to work well. It does not add
!important
to rules from the template, and it does add it to rules set by the style manager. This is the desired behavior.Do you agree? Should I submit a PR?
Cheers
The text was updated successfully, but these errors were encountered: