Problem/Motivation
#2958588: Off-canvas style resets are overriding styles (especially SVGs) resulting in display issues introduced off-canvas reset
#3291797: Refactor Drupal 10 settings tray / off-canvas to use modern CSS improved it to use modern CSS
As you can see here: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/misc/dialog/o...
the current implementation of the reset looks like this:
/*
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/3084859
* @preserve
*/
/**
* @file
* Reset HTML elements styles for the off-canvas dialog.
*
* @internal
*/
#drupal-off-canvas-wrapper *:where(:not(svg, svg *, .ck-reset *, [data-drupal-ck-style-fence] *, .ui-resizable-handle)) {
all: revert;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
line-height: 1.4;
}
#drupal-off-canvas-wrapper *:where(:not(svg, svg *, .ck-reset *, [data-drupal-ck-style-fence] *, .ui-resizable-handle))::after,
#drupal-off-canvas-wrapper *:where(:not(svg, svg *, .ck-reset *, [data-drupal-ck-style-fence] *, .ui-resizable-handle))::before {
all: revert;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
}
It already contains some excludes for special cases in core, but doesn't allow for contrib to opt-out of the resets, if needed.
That's what we should allow to do, by adding a general helper class to
Steps to reproduce
Need CSS in contrib not to be reset by the off-canvas layer
Proposed resolution
Provide a documented class in :not() selector to opt-out of the reset in contrib, just like the existing, predefined cases.
The class name should be discussed. Proposals:
- .drupal-off-canvas-wrapper-unreset
- .drupal-off-canvas-wrapper-noreset
- ...?
That might also solve the raised point in the comments here:
https://herchel.com/articles/new-drupal-core-refactored-canvas-dialog-css
And eventually it can save us from adding some further special cases and use the class instead?
Remaining tasks
- Discuss
- Implement
- Document
- Release
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Issue fork drupal-3395617
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:
Comments
Comment #2
anybodyComment #3
anybodyComment #4
anybodyComment #5
smustgrave commentedLike the idea. Think a framework manager would have to make the call.
Comment #6
bnjmnmThis solution is something I'd FEFM-approve some form of. Seems like a fairly gentle change that would address an annoying pain point with off canvas dialogs.
getComputedStyleto confirm styles are applied/not applied accordingly.class *so all child elements are reset immune?Comment #7
smustgrave commentedThanks @bnjmnm! Removing the tag for frontend framework.
Comment #8
anybody@bnjmnm thank you!
FYI: Guess I'm not the right one to implement and decide on this, as I'm not really experienced in frontend ;) My times writing bit more complex CSS are a decade ago, so please don't wait for my unqualified feedback here. I'll watch this issue and had the idea for this, yes, but my focus is elsewhere. Hopefully we have some frontend / CSS guys to take a look :)
Thank you all, I'm really happy you like the idea!
Comment #9
ndf commentedJust stumbled on this one when working on #3402171: Select2 css not applied inside off-canvas because Drupal core reset.css removes it (since Drupal core 10)
Does someone knows a workaround that can be used?
Maybe a method to replace core reset.css with an application specific one.
And imagine we have the exclusion class. How will the css of contrib look? Something like this:
Wouldn't that mean that all contrib css that might be rendered inside the off-canvas must be duplicated with the exclusion class prefixed. 🤔
Comment #10
justcaldwell@ndf — yes, you can replace core's off-canvas reset with your own as a workaround:
Then your-module-off-canvas-reset.css is just a copy of core's, with your selector added where needed:
Maybe not ideal, but it can make life much easier when you're trying to style for off-canvas.
Yes, I think so. That's why I'm hoping for a shorter classname, maybe something like
.drupal-noreset.Comment #11
justcaldwellOf course, if/when more projects take this approach, there will be conflicts.
Comment #12
bnjmnmI'm pro-BEM in many cases, but (as a front end framework manager / committer) I'm not opposed to approving something with a shorter classname. I think it's helpful to see at a glance if something has been un-reset and
.drupal-off-canvas-wrapper-noresetis a little too long for it to register quickly.For this to get further we'd need some kind of test coverage like what I requested in #6. If anyone following this issue is interested in doing this but unsure where to start (either writing the tests, or just getting it set up locally), find me on Drupal Slack and I can assist. This seems like a pain point worth solving sooner than later.
Comment #13
btully commentedDoes anyone have a workaround or solution to remove the reset.css, especially since it adds the nuclear "all: revert" and is injected into the DOM as an inline style?
There doesn't appear to be a way to override the css since one can't revert a revert.
I've also tried using the hook_css_alter() approach to remove the reset.css from the css array, but its contents get added and injected regardless.
Any help would be greatly appreciated.
Comment #14
robcarrHad to go crazy with
!importanttags to deal with the "all: revert". I knowComment #16
quietone commentedThe Settings Tray Module was approved for removal in #3576315: [policy, no patch] Move Settings Tray to a contributed project.
This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
The deprecation work is in #3576667: [meta] Tasks to deprecate Settings Tray and the removal work in #3581818: [meta] Tasks to remove Settings Tray module.
Settings Tray will be moved to a contributed project before Drupal 12.0.0 is released.