Re: [csswg-drafts] [css-shadow-parts] confirm browser support

> My question is, would that same selector match the same label, even if it was declared in one of the inner scopes? I guess the intention is that it does not, and that's the bit that makes a ::part(..) selector depend on where the selector is declared / in which scope it does live. 

It doesn't match, but that nothing do with scopes like you're implying. It's because, like I said in my previous comment, the part names are associated with the *shadow host*, **not** the element that the ::part() pseudo is pointing to.

The `x-foo` element has a `bar-baz-quux-label` part.  The `x-bar` element has a `baz-quux-label` part. The `x-baz` element has a `quux-label` part. And the `x-quux` element has a `label` part.  The fact that all of these parts end up pointing to the same deeply-nested element is irrelevant; they're completely independent facts associated with different shadow hosts.

> `shadowRoot.querySelector("[part=label]").matches("::part(label)")`

This will be false - it's the shadow root's host element that has a "label" part, and will match `::part(label)`.  And thus, since this selector is being run inside of the shadow root, and the host element is featureless, there's nothing you can put on the LHS of that pseudo-element that'll match.  (You could write `:host::part(label)`; that would be true.

(This is assuming that `.matches()` can ever return true when comparing elements and pseudo-element selectors; pseudo-elements that point to real elements is a pretty recent thing, and I don't know that this is well-defined. But it does make sense to me for this to work.)

> `shadowRoot.querySelector("[part=label]").matches("::part(bar-baz-quux-label)")`

Since this is being run inside the `x-quux`'s shadow root, apparently, there is no element that can match that selector *even if* you use `:host` (since the host element is `x-quux`, which doesn't have a "bar-baz-quux-label" part in its map).

> The issue is that ::part has multiple originating elements, depending on which scope are you matching from, if you allow forwarding.

This is the "pseudo-elements that point to real elements are new" confusion I just mentioned.  The originating element of a pseudo-element is the thing matched by the compound selector to its left.  In `::part()`, that's just the implicit `*`, but of course it can be more.  All four of the `::part()` examples you list are *different* pseudo-elements, each originating from a different host.  They just all happen to point to the same element.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2368#issuecomment-370034218 using your GitHub account

Received on Friday, 2 March 2018 19:52:43 UTC