-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Use a specific CSS class for the CSS reset mixin. #16856
Conversation
packages/edit-post/src/style.scss
Outdated
// The modals are shown outside the .block-editor wrapper, they need these styles | ||
.components-modal__frame { | ||
// Target the editor UI but exclude the metaboxes and custom fields areas. | ||
.block-editor-styles-reset { |
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'm a bit concerned about all these reset classes added everywhere. Can't we replace the previous .block-editor
with something more specific instead?
Also, ideally we should try to remove that "reset" entirely by moving the styles to the specific components making the components more reusable without relying on global styles.
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.
block-editor
contains the meta boxes and custom fields area. The only way would be to use a :not()
, and I'm not sure if that would be any better. Another approach would be to target each UI section individually, as it worked before. Something like:
.editor-post-permalink,
.edit-post-sidebar,
.editor-post-publish-panel,
.editor-styles-wrapper,
.components-popover,
.components-modal__frame { ... }
but that would produce several lines of CSS selectors, while a single class would produce way less lines. No strong preferences on my side.
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.
ideally we should try to remove that "reset" entirely by moving the styles to the specific components making the components more reusable without relying on global styles.
I'd agree. A bit out of the scope of this PR though.
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 have a preference for the :not
approach if it works otherwise listing the selectors is better. That way we avoid introducing a block-editor-styles-reset
class in a generic component like "modal". A Modal is agnostic of where it's being used.
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.
OK thanks, will try the :not()
approach as soon as I have some time.
Switched to the "list selectors individually" approach. |
packages/edit-post/src/style.scss
Outdated
.block-editor, | ||
// The modals are shown outside the .block-editor wrapper, they need these styles | ||
// Target the editor UI excluding the metaboxes and custom fields areas. | ||
.editor-styles-wrapper, |
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.
Should we replace this one with .edit-post-visual-editor
instead?
What about the text editor .edit-post-text-editor
?
I also noticed that the notices are shown outside that div should we add the reset for them or is it unnecessary:
.edit-post-layout__content > .components-notice-list,
.edit-post-layout__content > .components-snackbar-list
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.
What about the top bar as well?
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.
Should we replace this one with .edit-post-visual-editor instead?
Aren't they equivalent? If you mean for "semantic" reasons, no objections!
What about the text editor .edit-post-text-editor?
Yup, looks like it's needed for the permalinks UI there. Seems to me that's the only case of form controls within the text-editor area. Will add.
I also noticed that the notices ar
Yep, I did notice the notices. Not sure: is Gutenberg going to use form controls within the notices? It may need the box-sizing: border-box;
part.
What about the top bar as well?
Same: will there be form controls within the top bar? I think the top bar needs only the box-sizing: border-box;
part.
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.
Aren't they equivalent? If you mean for "semantic" reasons, no objections!
yes, mosty for semantic but also to prevent bugs as editor-styles-wrapper
can be used in several places to say "apply the editor styles here" (HTML prevew, block previews...)
Last commit should cover the points above. I'd tend to think the "reset" for Applying |
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.
Thanks, it seems to work as intended.
I agree with avoiding the global border-box and I tend to think we should try to do a push to remove all these resets at some point.
Thanks for the reviews! Yup, maybe we should consider to switch core to |
@youknowriad wouldn't this pattern fix a lot of box sizing inheritance issues? html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
} makes fixing a group things much easier since this PR caused two content box regressions so far |
@senadir I think the resets should be eliminated, this pattern is not that different it makes the component depend on a global style. Ideally, this is applied to each component so when a user loads the component in its own application, it works without requiring global resets. |
* Use a specific CSS class for the CSS reset mixin. * List selectors individually instead. * Add selectors for the missing UI parts.
* Use a specific CSS class for the CSS reset mixin. * List selectors individually instead. * Add selectors for the missing UI parts.
Description
After #14509, the CSS rules for form controls target also the metaboxes area, conflicting with styles provided by plugins.
See for example Yoast/wordpress-seo#13316
For now, the new form controls styles are used only in Gutenberg. Eventually, when these styles will be used in core, WordPress would expect plugins to honor the new styles but their CSS selectors would need to have a lower specificity.
In fact, WordPress styles form controls using CSS selectors with a relatively low specificity. For example:
input[type="text"]
. Instead, the selectors used in Gutenberg need to have a higher specificity. By doing so, their associated CSS rules tend to override the CSS provided by plugins.Once the new form controls styles will be in core, this problem will go away. For now, I'd like to propose to reinforce the principle that Gutenberg should do its best to not create conflicts with CSS provided by plugins.
This PR seeks to better scope the
reset
mixin:block-editor-styles-reset
: its sole responsibility is to apply thereset
mixinblock-editor-styles-reset
class on the relevant places in the UIOpen to better naming for the new CSS class, of course.
Added bonus
If plugins want to use the new form controls styles, they can opt for that by simply applying the new CSS class on their UI.
Test instructions:
Check all form controls have the new styles in the following places in the UI: