Reduce Specificity of Input Styles #18957
Labels
CSS Styling
Related to editor and front end styles, CSS-specific issues.
[Feature] UI Components
Impacts or related to the UI component system
[Type] Enhancement
A suggestion for improvement.
Describe the bug
This is in-kind with #10067; I am opening this ticket as a distinct example of over-specificity needing to be fixed.
The specificity of the block input styles causes custom styles which are correctly using simple classnames to get trampled over.
For example, let's say that I have a custom stylesheet which I have loaded in via
add_editor_style
. This stylesheet defines how inputs should look within a custom block, but uses a company-wide design library, and therefore has styles which cannot be modified just for the G'berg editor.This stylesheet has well-written selectors that only use classes such as
.client-input {...}
. This then gets converted to.editor-styles-wrapper .client-input {...}
after being passed throughadd_editor_style
. Core has an (ahem) comprehensive set of selectors for every single (or just about) type of input which are compiled to.block-editor-block-list__block input[type="number"]
.These appear to be defined here:
gutenberg/packages/base-styles/_mixins.scss
Lines 378 to 557 in 995aa3a
This leaves our custom styles with a specificity of
0,0,2,0
, whereas core has a specificity of0,0,2,1
which just barely overrides a well-written selector. This means that the inputs on my custom block are no longer in sync with the frontend and I have confused editors. My only options are to start a specificity war with G'berg's styles or use!important
. Both are terrible options and should be unnecessary.Expected behavior
I would expect the inputs to be styled only with a tag selector and a parent class. For example,
.block-editor-block-list__block input
or potentially apply the styles only to specific core blocks or to core input components.The text was updated successfully, but these errors were encountered: