Re: [csswg-drafts] [css-shadow-parts] Make `::slotted()` a combinator (#7922)

The CSS Working Group just discussed ``[css-shadow-parts] Make `::slotted()` a combinator``.

<details><summary>The full IRC log of that discussion</summary>
&lt;TabAtkins> lea: ::slotted() is a pseudo-element<br>
&lt;TabAtkins> lea: This doesn't really solve author's problems tho<br>
&lt;TabAtkins> lea: Four issue in the issue<br>
&lt;TabAtkins> lea: Can't use in querySelector<br>
&lt;TabAtkins> lea: Can't target children of slotted elements<br>
&lt;emilio> q+<br>
&lt;TabAtkins> lea: etc, lots because it's just a pseudo-element<br>
&lt;TabAtkins> lea: The WC community has chimed in and seem to think making this a combinator would solve these<br>
&lt;TabAtkins> lea: ::part() might have a similar approach but is more complicated to avoid exposing too much info, but ::slotted() refers to things in the light dom so it's not exposing anything too bad<br>
&lt;TabAtkins> lea: Discussing with fantasai, we don't see any issues spec-wise, but want to hear from impls<br>
&lt;castastrophe> q+<br>
&lt;TabAtkins> emilio: ::slotted() can also match in the shadow dom, it matches fallback content per spec (but unsure how well that's implemented)<br>
&lt;TabAtkins> emilio: Also as-is ::slotted() depends on which shadow tree you're in<br>
&lt;Rossen_> ack emilio<br>
&lt;TabAtkins> emilio: Also I think we do support ::slotted()::before, etc<br>
&lt;TabAtkins> emilio: probably not non-tree-abiding pseudos<br>
&lt;TabAtkins> emilio: If we don't support it, we should<br>
&lt;TabAtkins> castastrophe: My one concern with adding complexity to ::slotted(), there is already some confusion as to how it's applied<br>
&lt;TabAtkins> castastrophe: I have a codepen, like :first-child is first child in the DOM, not based on first in the slot<br>
&lt;lea> castastrophe: would love a link to the codepen!<br>
&lt;Rossen_> https://codepen.io/castastrophe/pen/rNKjLVj?editors=0010<br>
&lt;TabAtkins> castastrophe: So would be useful to clarify how things resolve relative to slot ordering, etc<br>
&lt;Rossen_> ack castastrophe<br>
&lt;fantasai> TabAtkins: I feel like that might be the reason we ended up designing ::slotted() the way it is, because you *can't* have sibling relationships<br>
&lt;fantasai> TabAtkins: unless it's a little more clear what context it's evaluated it<br>
&lt;fantasai> TabAtkins: but the rest of the issues lea brings up seem to be accidental damage<br>
&lt;lea> q+<br>
&lt;fantasai> TabAtkins: Not being able to descend into slotted element, no reason not to allow that<br>
&lt;castastrophe> Referenced codepen: https://codepen.io/castastrophe/pen/yLXpagw<br>
&lt;fantasai> lea: The point emilio brought up is good, that sometimes these elements can also be in the shadow DOM<br>
&lt;Rossen_> ack lea<br>
&lt;fantasai> lea: what if the slotted combinator didn't match such fallback content, only the author-provided elements<br>
&lt;fantasai> lea: but not sure if it satisfies the use cases, something to thin about<br>
&lt;TabAtkins> lea: I wonder if /slotted/ not matching fallback content would make sense. Not sure if it would still satisfy use-cases tho<br>
&lt;fantasai> TabAtkins: If you did want to distinguish other proposal to haveing a pseudo-class for whether using fallback content or not<br>
&lt;fantasai> TabAtkins: :has-slotted or something?<br>
&lt;TabAtkins> castastrophe: I think named slots is a bit of a challenge, what does light dom look like in multiple named slots<br>
&lt;lea> I think you can style fallback content with regular shadow DOM CSS, so it doesn't seem to be much of a problem at first glance?<br>
&lt;TabAtkins> castastrophe: The codepen does show the confusion about the elements having a relationship in the light dom vs in the slots<br>
&lt;lea> q?<br>
&lt;lea> q+<br>
&lt;Rossen_> ack lea<br>
&lt;TabAtkins> lea: I think you can style fallback content with regular CSS in the shadow.<br>
&lt;fantasai> TabAtkins: Emilio, you said that the ::slotted selector can match differently dependingon which shadow tree it's coming from, what did you mean?<br>
&lt;castastrophe> q+<br>
&lt;TabAtkins> fantasai: So frist thing to tink about is, if we add this, would we use the slotted relationship or the light dom relationship<br>
&lt;Rossen_> ack fantasai<br>
&lt;TabAtkins> fantasai: I think using the slotted relationship would be more understandable but not sure<br>
&lt;fantasai> lea: explain?<br>
&lt;fantasai> TabAtkins: Say you're slotting all the even elements<br>
&lt;fantasai> TabAtkins: and you asked :nth-child(2)<br>
&lt;fantasai> TabAtkins: is this the 2nd slotted item, or the 2nd item in the original DOM?<br>
&lt;fantasai> lea: we'd need to figure out what the author expectations are<br>
&lt;emilio> q+<br>
&lt;fantasai> TabAtkins: I expect there's complexity in evaluating on the slotted list<br>
&lt;TabAtkins> lea: Intuitively to me, as an author, it seems like the light dom relationship makes more sense<br>
&lt;fantasai> lea: intuitively as an author, it seems to me the light DOM relationships makes more sense<br>
&lt;fantasai> TabAtkins: Wanting to style first/last items in the slot using :first-child/:last-child is reasonable case<br>
&lt;lea> q+<br>
&lt;Rossen_> ack castastrophe<br>
&lt;fantasai> castastrophe: There's a lot of confusion over named slots<br>
&lt;fantasai> castastrophe: e.g. if you pull things into named slots, currently :first-child is only if it's the first child in the light DOM<br>
&lt;fantasai> castastrophe: but not if it's the first child in the slot<br>
&lt;fantasai> castastrophe: I think we'd need to be very clear in the spec<br>
&lt;fantasai> scribnick: fantasai<br>
&lt;fantasai> scribenick: fantasai<br>
&lt;Rossen_> ack emilio<br>
&lt;fantasai> emilio: Regarding what we talked before, matching where the selector is<br>
&lt;fantasai> emilio: in the case of nested slots, it woudl jump across to slots in the current shadow tree<br>
&lt;fantasai> emilio: that's the behavior I was talkinga bout before<br>
&lt;fantasai> castastrophe: if you have a slot that's passing content to a shadow template that also has.. if you have multiple?<br>
&lt;fantasai> emilio: from outer tree, slotted pseudo would cross that nested slot<br>
&lt;fantasai> emilio: the outer shadow tree<br>
&lt;fantasai> emilio: so you could still style the slotted contents ...<br>
&lt;fantasai> emilio: I need a whiteboard to reason about nested slots!<br>
&lt;fantasai> emilio: but I'm sure we jump across to the right scope<br>
&lt;fantasai> emilio: that scope is dependent on the tree that we're looking at right now<br>
&lt;fantasai> Rossen_: I'm hoping that made sense to you, Tab?<br>
&lt;castastrophe> q+<br>
&lt;fantasai> TabAtkins: I don't know that's necessarily right...<br>
&lt;fantasai> TabAtkins: I'd have to look up again the slot assignment algo<br>
&lt;fantasai> TabAtkins: I forget, if you're in nested slot, if we match the slot element from higher up or the things slotted in that element<br>
&lt;TabAtkins> Oh, it's after flattening<br>
&lt;Rossen_> ack fantasai<br>
&lt;TabAtkins> the elements can def come from multiple trees tho<br>
&lt;TabAtkins> q+<br>
&lt;fantasai> fantasai: I think we definitely need ability to style based on the slotted relationships<br>
&lt;fantasai> fantasai: as brought up before<br>
&lt;fantasai> fantasai: if you're pulling a subset of items into a slot, e.g. into a list<br>
&lt;Rossen_> Zakim, close queue<br>
&lt;Zakim> ok, Rossen_, the speaker queue is closed<br>
&lt;fantasai> florian: and you want to style every other item with :nth-child(), you want to get every other slotted item<br>
&lt;fantasai> s/florian/fantasai/<br>
&lt;fantasai> fantasai: not a random set of items based on what was selected or not from the light DOM<br>
&lt;fantasai> fantasai: similarly, as was brought up earlier for first/last child styling<br>
&lt;bkardell_> hmm<br>
&lt;TabAtkins> fantasai: We might also want the original light dom relationship<br>
&lt;TabAtkins> fantasai: But definitely think we need based on the slotted relationship<br>
&lt;bkardell_> Does that not imply that you know something about the dom inside the shadow root then?<br>
&lt;TabAtkins> fantasai: Since ::slotted() currently works based on light dom, one possibility would have ::slotted stay with that, but /slotted/ shift into "the slotted view of the world"<br>
&lt;TabAtkins> fantasai: we've discussed different ways to shift your view of the world<br>
&lt;bkardell_> Rossen_: yeah?<br>
&lt;fantasai> s/world/world, one of which was using subtrees under pseudo-elements<br>
&lt;fantasai> lea: there are two relationships, one based on relationships in light dom or slotted tree<br>
&lt;fantasai> lea: is one ??? the other?<br>
&lt;TabAtkins> lea: There's these two behavior - based on light dom, based on slotting - is one much easier to implement?<br>
&lt;fantasai> s/???/easier to implement than/<br>
&lt;fantasai> Rossen_: Does anyone have an answer?<br>
&lt;fantasai> emilio: slotted thing is new thing, so you need to somehow decide on ?? child matching vs<br>
&lt;fantasai> emilio: other thing is storage of slotted children different<br>
&lt;fantasai> Rossen_: sounds like light DOM is easier<br>
&lt;bkardell_> q+<br>
&lt;fantasai> emilio: but probably not impossible to make slotted work<br>
&lt;Rossen_> ack lea<br>
&lt;Rossen_> ack castastrophe<br>
&lt;fantasai> castastrophe: I agree, I think light DOM would be less complex<br>
&lt;fantasai> castastrophe: because that relationship is flat<br>
&lt;lea> Light DOM is easier to implement because that's the current behavior of ::slotted(), but does anyone have any feel of the implementability of the other option?<br>
&lt;fantasai> castastrophe: I was just making notation, but I think the nested shadow DOM is getting the slot element, not the slotted content<br>
&lt;fantasai> castastrophe: it renders it correctly, but when using CSS selectors<br>
&lt;fantasai> castastrophe: you don't have access to the slotted content until further down<br>
&lt;fantasai> castastrophe: So I think it's just the tag &lt;slot> in nested shadows<br>
&lt;fantasai> castastrophe: so I think we need to open a new issue for how we build styles for named combinators<br>
&lt;fantasai> castastrophe: need to identify the named slot and the combinator in the same query<br>
&lt;emilio> I need to check what this `while` loop is doing then: https://searchfox.org/mozilla-central/rev/af78418c4b5f2c8721d1a06486cf4cf0b33e1e8d/servo/components/selectors/matching.rs#464-468<br>
&lt;Rossen_> ack TabAtkins<br>
&lt;fantasai> TabAtkins: So Cas, if you've been seeing the slot element matched by ::slotted in deeply nested situations, that is spec violation<br>
&lt;fantasai> TabAtkins: because should flatten and get the real elements<br>
&lt;fantasai> TabAtkins: so the slotted inside the nested part should see the original light dom elements, not the slot<br>
&lt;fantasai> Rossen_: It sounds like we'll end issue without a concrete resolution<br>
&lt;fantasai> Rossen_: let's pick it up again on Wednesday<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7922#issuecomment-1466432586 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 13 March 2023 16:03:43 UTC