Problem/Motivation
In the postcss file core/themes/stable/css/core/dialog/off-canvas.reset.pcss.css, properties for HTML elements rendered in the off-canvas dialog are reset using all: initial;. This is then followed by box-sizing: border-box. But in the generated css, all: initial; is not followed by box-sizing: border-box and this means box-sizing is the CSS standard default "content-box". If your theme is based off the stable theme, you may find that elements rendered within the off-canvas dialog do not have correct dimensions. For us, we have custom themes based on the stable theme and we are seeing incorrectly sized buttons output by the Moderation Sidebar contrib module.
Steps to reproduce
Compare the postcss with the generated css.
In core/themes/stable/css/core/dialog/off-canvas.reset.pcss.css we have this:
#drupal-off-canvas {
& span,
& applet,
...
...
...
& input,
& select,
& textarea {
all: initial;
box-sizing: border-box;
text-shadow: none;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: initial;
&:after,
&:before {
all: initial;
box-sizing: border-box;
text-shadow: none;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: initial;
}
}
}
If we now look at the generated css in core/themes/stable/css/core/dialog/off-canvas.reset.css we have this:
#drupal-off-canvas span,
#drupal-off-canvas applet,
...
...
...
#drupal-off-canvas input,
#drupal-off-canvas select,
#drupal-off-canvas textarea {
...
...
...
box-sizing: content-box;
box-sizing: border-box;
...
...
...
all: initial;
...
}
The all: initial; line is not followed by box-sizing: border-box as it is in the postcss file. So box-sizing is effectively set to be content-box by the last all: initial; line.
Proposed resolution
Fix PostCSS processing somehow so that the box-sizing: border-box line that should follow all: initial; is preserved.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3340931-off-canvas-reset-2.patch | 21.06 KB | glugmeister |
| #3 | 3340931-off-canvas-reset.patch | 3.62 KB | glugmeister |
Issue fork drupal-3340931
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3340931-stable-themes-off-canvas
changes, plain diff MR !3495
Comments
Comment #2
glugmeister commentedComment #3
glugmeister commentedI've had a go at creating a patch for this. Since I'm not sure how to fix postcss processing so that the
box-sizing: border-boxline followingall: initial;is preserved, I've just moved it to a separate rule targeting all off-canvas html elements. I also removed a superfloustext-shadow: none;that also followed theall: initial;. The post css processing convertsall: initial;into a whole list of individual properties (for browsers that do not support the css 'all' property) and sotext-shadow: none;gets set anyway in the generated css.Comment #4
glugmeister commentedSecond attempt at a patch. In the first attempt, the additional rule for setting box-sizing: border-box did not have enough specificity.
Comment #5
glugmeister commentedComment #6
markconroy commentedI'm not sure of the exact issue here. It seems our processor is taking our
box-sizing: border-boxand generatingThe first
content-boxshould not be generated because we then immediately placeborder-boxafter it. But the finalall: initialseems very dangerous, as I presume it's overriding everything above it.Adding 2 issues that seem to be related.
Comment #7
markconroy commentedI think we can fix this by editing /core/.stylelintrc.json and moving
allto the top of the "order/properties-order" listing. That would mean that "all" comes first to reset what it needs to reset, but then any overrides we need to this, will come after it.I'm honestly not sure if this would be a breaking change and not allowed in Stable in D9 or if this is actually a feature that we need to have in future in our stylelint for D10.
I'll create an MR for this at least, so we can test it.
Comment #9
quietone commentedSince stable has been removed from core should this be in the Stable 9 component?
Comment #10
markconroy commented@quietone this issue is about stable in d9.5, so I think it can remain here for now. Once 9.5 is no longer supported, I think we can mark this closed: won't fix as it will not be an issue in a contrib theme.
Comment #11
smustgrave commentedSince technically D9.5 is still supported don't see an issue with merging here. But a follow up with have to be opened for the contrib version.
Comment #12
larowlanThis looks good to me and makes sense, all should always come first.
I wonder if we need the same stylelint change in D10+ too?
Tagging for FEFM review.
Comment #13
amber himes matzLooks like this MR needs to be rebased onto 9.5.x, as the merge is currently blocked according to the MR in GitLab. (Clicking the Rebase button didn't work for me.)
Comment #15
pyrello commentedI was able to rebase the MR, so I undid the issue tags and status changes. To be able to rebase the MR, I had to click the "Get push access" under the issue summary.
I'm uploading a file-based patch to use for my team's project, which can safely be ignored.
Comment #16
bnjmnmFEFM here. I agree that having the
all: initial;after many lines of styles was a poor implementation that needs fixing. I'm also concerned that making such a change is potentially disruptive in a way that breaks the "fence" promised by Stable themes.There are sites/themes that may experience regressions if this (clearly not-ideal) CSS changes. Among other things, there may be styles that While it's true the issue fixed here could be classified as a bugfix, there may be themes based on Stable that now expect the
content-boxsizing.I would immediately sign off on a version of this that changed the /core CSS but not the Stable theme CSS. To change Stable I think there would need to be a deeper risk/benefit assessment. Perhaps the core change can happen here, and the potentially longer discussion of updating Stable can be done in a followup.
Comment #18
markconroy commentedI'm going to close this issue since it belongs to Drupal 9.5 which is no longer supported and our `/core/.stylelint.json` file for D10/D11 does not include the `all` property. in the "order/properties-order" definition.
===
Thanks to Code Enigma for sponsoring my time to work on this.