Re: [WICG/webcomponents] Clarification which pseudo selectors work with `::slotted` and `::part` (#934)

Just one note before you read the following and that's that browsers may not implement the spec entirely, but as for what's actually specified this is what I could find.

So the stuff about complex/simple selectors is actually to do with stuff that goes inside of the call. In `::slotted`'s case this is actually neither of them but rather specified to be a [compound selector](https://drafts.csswg.org/css-scoping/#slotted-pseudo). The definition of each of these types of selectors [is here](https://drafts.csswg.org/selectors/#structure).

As for what pseudo selectors work after `::slotted()`, as it selects elements, any pseudo-class that works on elements should work on `::slotted()`. Although it's weird because as it accepts a compound selector all pseudo classes can already be inside the `::slotted()`, i.e. `::slotted(:visited)` should be the same as `::slotted(*):visited`. This should probably be clarified in that spec as to what this is supposed to accept.

For pseudo elements that work after `::slotted()` the [spec also says](https://drafts.csswg.org/css-scoping/#slotted-pseudo) it is precisely [tree-abiding pseudo elements](https://drafts.csswg.org/css-pseudo-4/#tree-abiding), so that includes things like `::before`/`::after` and everything else in section 4 there. Now `::part` isn't specified as a tree-abiding pseudo element but [it is wanted](https://github.com/w3c/csswg-drafts/issues/3896).

Now for `::part()`, the actual inside of `::part()` doesn't accept a selector, it just takes a list of identifiers which are just a list of names for corresponding `part="name"` or `exportparts="innerName:name"` attributes inside the shadow root.

The pseudo classes `::part` supports is more explicit, essentially `::part` is also an element selector, so anything that works on elements should work, except that `::part` [specifically bans structural pseudo classes](https://drafts.csswg.org/css-shadow-parts/#part).

The pseudo elements `::part` is also [specifically specified](https://drafts.csswg.org/css-shadow-parts/#part) to allow any pseudo elements EXCEPT for other `::part`s.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/934#issuecomment-906063140

Received on Thursday, 26 August 2021 03:25:34 UTC