Open rejhgadellaa opened 1 month ago
Having it be a pseudo-element with children seems a little more complex than needed, I think? I think we can get the same functionality with a pseudo-class that matches elements in the top-layer list. We can make it functional as well, taking an an+b argument selecting based on top-layer index.
That is, dialog:top-layer
would match when the dialog was in the top layer; dialog:top-layer(last 1)
would match the last one in the list (which is topmost).
Am I missing something that makes this not work?
I think that the benefit of going with a pseudo-element would be that it automatically enables the use of any existing 'state' CSS selector (:nth-child
, :has
, etc) instead of having to spec and implement that for the pseudo-class?
For example, this should automatically work if ::top-layer
would be a pseudo-element:
/* Style popovers if a dialog is also present */
::top-layer:has( dialog ) [popover] {
...
}
# Am I missing something that makes this not work?
The discussion in #7319 started with the suggestion to add :top-layer
but eventually we moved away from that. This comment summarizes it nicely:
The TL/DR is that OpenUI roughly agreed with CSSWG that perhaps
:top-layer
isn't a good name. We discussed alternatives like:popup-open
(specific to the Pop-up API), or just:open
(which should apply to other cases like<summary>
/<details>
). We also discussed the::top-layer
pseudo element https://github.com/w3c/csswg-drafts/issues/7319#issuecomment-1168531437, but found it too non-standard and confusing for developers.
@bramus Given https://nerdy.dev/have-a-dialog, if we want to style the <body>
that way when a modal dialog is open, but the <dialog>
is in (nested) shadow DOM, having the ability to do body:has(::top-layer dialog) { scale: 0.8 }
etc would be awesome. Otherwise you'd have to use JS to add a class on the body when a dialog is open.
I'm thinking of web component design systems that would benefit from this CSS ability.
This is a continuation of #7319.
I request that a
::top-layer
pseudo element is added. As Bramus proposed:I've created a codepen that demonstrates a use case for being able select the top-most
<dialog />
and prevent 'stacking' of multiple::backdrop
s:https://codepen.io/rejh/pen/LYKPvNr
Thank you!
Edit: CC @bramus