Skip to content

[css-scoping-1][css-shadow-parts-1] Can the non-functional :host be compound? And should ::part() select within its own shadow root? #9981

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

Closed
knowler opened this issue Feb 20, 2024 · 2 comments

Comments

@knowler
Copy link

knowler commented Feb 20, 2024

Currently in all browsers, within a shadow root, a selector such as :host::part(something) will select parts within that same shadow root. I’m curious if this is intentional as I cannot tell from the spec that the non-functional :host pseudo-class can be a compound selector like this. Admittedly, this is a nicer API than using an attribute selector, so I am happy if that’s the case. Further, in Firefox, a selector like ::part(something) on its own within a shadow root can select parts within the same shadow root. This seems maybe a bit problematic since then it could select parts within two shadow roots at the same time (e.g. a nested shadow root as well).

Demo for each case mentioned

@cdoublev
Copy link
Collaborator

cdoublev commented Feb 20, 2024

This comment probably answers your question about compounding :host:

:host will only ever match anything if these hold:

  1. :host appears in the leftmost compound selector.
  2. :host is the only simple selector in that compound.

"For the purpose of Selectors, a shadow host also appears in its shadow tree, with the contents of the shadow tree treated as its children. (In other words, the shadow host is treated as replacing the shadow root node.)

edit: it answers your question, assuming :host::part(), :host::before, etc. are not real compound selectors but a combination of a compound selector and a pseudo-compound selector, as if :: were a combinator.

@knowler
Copy link
Author

knowler commented Feb 20, 2024

I just found the Firefox bug for the bare ::part() selector working in its own shadow root—looks like that’s not supposed to work even though they’ve set it to wontfix. I’m going to close, but to summarize:

  1. The compound selector :host::part() matching in its own root is valid (and intentional).
  2. The bare ::part() selector matching in its own root is invalid and there’s a bug for Firefox already reported.

@knowler knowler closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants