Skip to content
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

[css-nesting] Make nesting work in :host rules #9496

Open
sorvell opened this issue Oct 18, 2023 · 6 comments
Open

[css-nesting] Make nesting work in :host rules #9496

sorvell opened this issue Oct 18, 2023 · 6 comments
Labels
css-nesting-1 Current Work

Comments

@sorvell
Copy link

sorvell commented Oct 18, 2023

When styling elements in Shadow DOM, combinators can be used with the :host selector to select elements in the shadowRoot (e.g. :host > div { ... }). These rules do not currently work with CSS nesting.

It's not clear if this is a bug or omission or intentional (hope not) via the language at https://drafts.csswg.org/css-nesting/#nesting.

Note that the behavior of combinators next to :host is somewhat unique in that the tree traversed is the shadow tree, not the tree in the scope of the host element. This likely(?) means this needs a specific callout in the spec.

@Loirooriol
Copy link
Contributor

I think this is like #9025, but for & instead of :scope.

@Loirooriol Loirooriol added the css-nesting-1 Current Work label Oct 19, 2023
@tabatkins
Copy link
Member

What selectors don't work, precisely? There's already spec text defining how Nesting interacts with things like :host:

The nesting selector is capable of matching featureless elements, if they were matched by the parent rule.

Is your problematic example already covered by that text? If so, it's an impl bug. If not, I'd love to see it, so we can see if we can address the issue.

@Loirooriol
Copy link
Contributor

It seems that browsers haven't implemented that :is(:host) should work, and they are internally using :is() for nesting.

@tabatkins
Copy link
Member

tabatkins commented Oct 20, 2023

Ah, it's not actually clear in the spec text that :is(:host) should work. (It obviously should work.) That's an obvious fix; I'll open an issue against Selectors. (see next comment)

@tabatkins
Copy link
Member

Nm, it does indeed say that it should work, in the definition of "featureless"

@emolr
Copy link

emolr commented Aug 6, 2024

This seems to work correctly in Chrome and Firefox now.
Safari is still discarding all nested selectors from host, eg. :host { .my-selector {...} }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-nesting-1 Current Work
Projects
None yet
Development

No branches or pull requests

4 participants