-
Notifications
You must be signed in to change notification settings - Fork 719
[css-shadow-parts] Make ::slotted()
a combinator
#7922
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
Comments
All of those targeting options sound AMAZING! 😍 When you say "make it a combinator", what does that really mean? Is that a syntax change? Is that an interpreter change? Something else? If this is an interpreter change, is there room to as part of this investigation to look into ways that we might alter the specificity of a If this allows for targeting descendants, is there any benefit to investigating the inclusion of One other |
Combinators are things like
The problem is not that its specificity is low, but that it operates on an entirely different level of the cascade. @mirisuzanne, @fantasai and I were discussing how to address this just the other day, but it's orthogonal to this. If you have any pointers to discussions about this problem (besides the issue I linked to above) they would be useful.
This is also a separate issue, but any pointers you may have are useful, so we can open a new issue to discuss it! PS: I merged your two consecutive comments, hence the deleted comment notice below 😊 |
Yes, please. A thousands times yes. |
Sorry for not being more clear here:
Does that mean we would alter the interpretation of I'll hunt down related issues/content on those other points, as I know they've been brought up in other contexts, I just can find them just this minute. |
This would solve so many problems our design systems team has come across. I could list 5 reports just from the last week! |
Not sure I fully understand your question, but we can certainly not remove Btw no need to use a placeholder symbol, for something like this I don't think more ascii art is appropriate, something like One small downside of a combinator is that you need to target the element the combinator operates on, i.e. the slot element, which makes for somewhat awkward syntax e.g.
Please do! |
A major issue we're running into is lightdom (i.e. app-level) css interfering with our component styles. There are some cases where we can We're offering workarounds with our lightdom stylesheets, but we'd prefer not to have those at all, and just do everything in shadow DOM, which would be easier to use, more performant, and more maintainable. Maybe @heyMP would like to elaborate |
I see. So, making |
yes, exactly. it would remove the need for more-error-prone lightdom stylesheets, and given a later proposal to somehow bump the priority of ::slotted, would allow us to write-once-run-everywhere at greater scale and pace. |
As mentioned above, the low specificity of Other than that, the ability to have complex selectors will go a long way. We could eliminate the requirement of having to load a lightdom.css file just to target elements in an unordered list. 😀 |
Is there overlap with #7346 ? |
Yes, but the ability to add combinators after |
This is probably out of scope for this This
|
@heyMP Very interesting! I hadn't considered a use-case like this yet but it makes perfect sense. Keyframes are CSSRules and so it's being defined inside a different tree than the light DOM content. |
@heyMP Regarding this point, I have definitely felt this pain in the past though on other projects, I quite like and embrace that low specificity. Makes us evaluate what kind of light/shadow DOM support a component (or library) wants to enforce. |
@heyMP @bennypowers Did I set up this demo on par with what you found in your keyframes example? https://codepen.io/castastrophe/pen/rNKjLVj?editors=0010 |
Dove deep into this last night. Here's the summary of our findings: Keyframe defined in the shadow DOM scope:
Keyframe defined in a style tag assigned to the slot:
Found no examples of a keyframe defined in the global DOM scope crossing the boundary into the shadow DOM. With that, I'll stop squirreling on this topic as it feels unrelated to the primary goal laid out in the description. |
Can you open a new one though? This is an important topic that deserves separate consideration. |
The CSS Working Group just discussed The full IRC log of that discussion |
@LeaVerou Won't this allow |
I can’t help but find |
(The remaining ASCII glyphs are almost certainly more valuable to save for new simple selector prefixes rather than combinators.) |
Well once upon a time there was |
The CSS Working Group just discussed The full IRC log of that discussion |
Uh oh!
There was an error while loading. Please reload this page.
Currently
::slotted()
is a functional pseudo-element, which causes no end of problems:querySelectorAll()
,closest()
, `matches(), etc):has(/slotted/ *)
The intended way of going from one element to another based on their relationship in the DOM is combinators. That's why combinators exist. Even introducing a combinator that is just as restricted in syntax as the pseudo-element (minus the restrictions that are inherent to it being a pseudo-element) fixes many of these problems, and paves the way for relaxing the restrictions even further down the line.
Sure, it is a wart to have a combinator with a restricted syntax, but it's only one wart (and possibly even a temporary one) which allows us to solve numerous others.
Sure, all of these can be special-cased for
::slotted()
, but that adds cognitive overhead for authors and complicates implementations in a way that is (a) perpetual (special casing needs to persist forever) and (b) unbounded — these special cases will only keep increasing.Yes, we can't get rid of
::slotted()
for the foreseeable future, even if we add this, but at least we can stop special casing stuff around it, and just direct authors to/slotted/
. And who knows, maybe even down the line usage could drop below the axing threshold.Other notes:
:slotted(...)
a pseudo class #7305 . However, unless @fantasai and I are missing something, it should be possible to make it a combinator (/slotted/
), which would address all of the above.::part()
has similar issues, but is not equally trivial to turn into a combinator because that would give the outside world access to too much of the shadow subtree, but::slotted()
refers to the light DOM so doesn't have these problems.The text was updated successfully, but these errors were encountered: