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-shadow-parts] match parts of the current shadow root #7955

Closed
jonathantneal opened this issue Oct 26, 2022 · 5 comments
Closed

[css-shadow-parts] match parts of the current shadow root #7955

jonathantneal opened this issue Oct 26, 2022 · 5 comments

Comments

@jonathantneal
Copy link
Contributor

jonathantneal commented Oct 26, 2022

Background: To match a shadow part from outside its own shadow root, we use the ::part() pseudo-element selector.

::part(day weekend) {
  color: blue;
}

That selector will have a calculated specificity of 1 Type.

Issue: To match a shadow part from within its own shadow root, we use CSS attribute selector. It feels rather inelegant because of how dissimilar it is to the ::part() selector.

[part~="day"][part~="weekend"] {
  color: blue;
}

That selector will have a different calculated specificity; 2 Classes. To match the ::part() specificity of 1 Type, we must add additional selector trickery.

:where([part~="day"][part~="weekend"]):not(_) {
  color: blue;
}

That selector feels very long, cryptic, and too dissimilar from its light ::part() counterpart.

Recommendation: May we add a :host-part() pseudo-class selector to match elements with the given parts?

:host-part(day weekend) {
  color: blue;
}

Edit: @Westbrook was kind enough to point out a far more readable fallback. It won’t match the suggested specificity, but it is far more readable.

:host::part(day weekend) {
  color: blue;
}
@brandonmcconnell
Copy link

+1

Makes total sense to me. This API would greatly simplify working with Shadow DOM parts. 👏🏼

@emilio
Copy link
Collaborator

emilio commented Oct 26, 2022

Those two specificities don't compete because the style sheets are in separate trees, fwiw.

@emilio
Copy link
Collaborator

emilio commented Oct 26, 2022

:host::part(..) should work in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1624968) and it's a bug that it doesn't work in other browsers afaict.

@emilio
Copy link
Collaborator

emilio commented Oct 26, 2022

Though apparently other browsers also fixed it?

@jonathantneal
Copy link
Contributor Author

Thank you, @emilio. If evergreen browser support for :host::part() is good, then I will close this, as the value for the syntactic sugar would be quite low.

Those two specificities don't compete because the style sheets are in separate trees, fwiw.

Ah, thank you. Like ::before and ::after having explicit combinators, I forget this quality of CSS. I appreciate the refresher.

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

3 participants