Skip to content

[css-shadow-parts] Can I use ::slotted and ::part together? #5161

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
runarberg opened this issue Jun 4, 2020 · 3 comments
Closed

[css-shadow-parts] Can I use ::slotted and ::part together? #5161

runarberg opened this issue Jun 4, 2020 · 3 comments

Comments

@runarberg
Copy link

From my understanding, the compound selector allows selecting a pseudo element. So I’m wondering if we can select a shadow part of a slotted custom element?

::slotted(my-element::part(my-shadow-part)) {
  /* ... */
}

I’ve tried this in Chrome and Firefox and it doesn’t work. I’ve also tried the selector as if ::part was tree abiding:

::slotted(my-element)::part(my-shadow-part)

And unsurprisingly it didn’t work either.

My question is: Is the former example a bug in the implementation or is the ::part pseudo element not accessible with ::slotted by design?

@emilio
Copy link
Collaborator

emilio commented Jun 4, 2020

I can see how this could be useful, in principle at least...

In practice it's slightly annoying to do implementation wise, as the part itself could be slotted, and this increases a lot the amount of trees that rules can come from for a given element (which in practice can have performance implications)... Probably not impossible though.

@runarberg
Copy link
Author

runarberg commented Jun 5, 2020

Note that I was only experimenting, there are other ways of achieving my goal. E.g. my custom element could dynamically set a property on the child custom element and then I can just move the rules to the shadow styles of the slotted element.

What I ended up doing though is just export a global stylesheet with my library and moved the rules to there:

<my-element>Here the part has a default style</my-element>
<my-container>
  <my-element>
    A shadow part is styled differently because we are a slotted child of
    <code>&lt;my-container&gt;</code>.
  </my-element>
</my-container>
/* exported global stylesheet */
my-container my-element::part(my-shadow-part) {
  /* ... */
}

@emilio
Copy link
Collaborator

emilio commented Jun 23, 2020

This is a dupe of #3896, closing as such.

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