You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's define the behavior of ::slotted (a tentative name).
I am aware that CSS Scoping should define it, but let's have a rough consensus here.
I remember that I had discussion, maybe in www-style?, that we should make ::content take only a simple selector, instead of a selector. Polymer guys told us that styling a direct child of an insertion point is the only use case of ::content in Polymer.
e.g. ::content(div)
That should be interpreted as ::content > div in the previous syntax.
We no longer support a selector as its argument, like ::content(div p)
We might want to make ::slotted have this restriction because this makes the implementation simpler.
See also #308 (comment) because the definition of ::slotted will depend on those incoming changes.
I recently did a search through the Basic Web Components project looking for where we currently use ::content. We concur with Polymer: the only cases where we currently use ::content are trying to style the direct children of an insertion point.
Regarding the name of this selector, it seems that the term "slotted" here is being used as a synonym for "assigned". For consistency with the use of "assigned" in the spec, and with existing API members such as getAssignedNodes(), perhaps this selector could be called ::assigned. That would reduce the number of terms and concepts a developer needs to learn here.
Yeah, if we're making this pseudo element flatten slot elements' assigned node lists, then we should probably refrain from using the term "assigned". Also, someone pointed out that "assigned" might sound too generic while "slotted" sounds a lot more related to slot elements.
For Shadow DOM V0, the following pattern is often used: ::content > div { color: blue; }
The color: blue is applied to <div>, not the parenting <content>.
(and in the selector matching, ::content matches <content>, of course)
In the proposed ::slotted() for V1, an author would expect the same as above by: ::slotted(div) { color: blue; }
If @hayatoito's comment above is adopted, the color: blue is applied to <div>
(which is node B in the comment), not the parenting <slot> (which is node A).
Obviously if an author wants to style <slot> element itself,
it can write slot { color: blue; } and no fancy pseudo class/element should be required,
so the matching logic in the above comment should be correct, but let me confirm.
Another question: Do we allow ::slotted without function-style parameter?
In that case, any element slotted under <slot> would match the rule?
In the default slot case, text node could match the rule, then?
E.g. ::slotted would be almost equivalent to ::slotted(*), but if a text node is slotted under a <slot>, it might be different.
<div>
:shadow-root
<slotname="blue"></slot><slot></slot><divslot="blue">This text should be in blue.</div><div>(1)Is this color blue?</div>
(2)Is this color green?
</div>
This did not work, as intended, IMO. We might not want to support this because a pseudo element, which "::before" matches, is not a member of a distributed nodes of SLOT. This should not match.
or ::slotted(div.foo)::before ?
How to support this kind of consecutive pseudo elements is up to each pseudo element. In this case, it's up to "::slotted" pseudo element.
In a general rule, selectors have a limitation about what can be followed after a pseudo element.
I'm +1 not to support this unless we have a strong use case.
I'd like "::slotted" be valid only when it is the last item in a selector, as of now.
Right, that's because :host() always represents the host element; it just uses the argument to query the tree to see if it should match or not. Putting ::before inside the argument wouldn't make any sense - you dont' want to check if an ancestor has a ::before pseudo-element.
::slotted, on the other hand, uses its argument to decide which of its assigned slotables it's supposed to represent. As such, it makes a little more sense to have ::before inside.
(At least, it makes as much sense as using doing something like :matches(.foo, .foo::before), which is allowed.)
I don't have a problem with ::slotted(.foo)::before, it just means dealing with chained pseudo-elements. Which we had before, so it's probably not a problem.
I'll also note that if you're drawing parallels between :host() and ::slotted(), authors probably will too - they select up and down outside the shadow tree. Having them work as similarly as possible (main difference being the number of colons) is probably good for comprehension. So that's an argument for ::slotted()::before.
The descendants of a shadow host (its light tree) must not generate boxes in the formatting tree. Instead, the contents of the shadow tree generate boxes as if they were the contents of the shadow host instead.
In several instances in shadow DOM, elements don’t have element parents (instead, they may have a shadow root as parent, or something else). An element without a parent, or whose parent is not an element, is called a top-level element.
While a shadow host’s light tree does not generate boxes normally, its light tree direct children can be explicitly pulled into a shadow tree and forced to render normally. This is done by marking the child as slotable and then, in the shadow tree, creating a slot set to receive the slotable, making the element assigned to the slot. (Anonymous text nodes that are direct children are always slotable.)
Since the actual logic, "Which elements generate a box?", should be explained by the concept of the flat tree ,
can we avoid to explain that in details here?
I'm wondering how to state it simply in css scoping. The current Shadow DOM spec has the followings in the section of Flat trees:
A document flat tree is a flat tree whose root node is a document
A node is in a document flat tree if it participates in a document flat tree.
Unless an element is in a document flat tree, the element must not create any CSS box.
In resolving CSS inheritance, an element must inherit from the parent node in the flat tree, if applicable.
User agents must use the document flat tree in the visual formatting model, instead of the document tree.
I think we should upstream these sentences to CSS scoping. I guess these sentences need to be refined somehow to match the css scoping world.
DOM Standard does not need a flat tree. I think only css scoping is a client of a flat tree. Thus, eventually, we need to upstream a flat tree to CSS.
3.1. Shadow DOM Selection Model
Elements in the DOM have zero or more shadow trees.
This can be:
Elements in the DOM have zero or one shadow tree.
Yeah, multiple shadow trees are removed.
Otherwise, we might want to omit this because it looks a duplication of the HTML Standard.
3.1.1. Shadow Hosts in a Shadow Tree
For the purpose of Selectors, a shadow host also appears in each of its shadow trees, with the contents of the shadow tree treated as its children. If an element has multiple shadow trees, it appears in each shadow tree’s context independently; each shadow tree sees itself as the contents of the shadow host, not the other shadow trees.
This can be:
For the purpose of Selectors, a shadow host also appears in its shadow tree, with the contents of the shadow tree treated as its children.
because multiple shadow trees are removed.
3.1.2. Slots and Slotted Elements in a Shadow Tree
If a slot is not assigned any of its shadow host’s children, that slot’s own children are assigned to it. Otherwise, a slot’s DOM children must not generate any boxes, as if they were display:none.
Slots can, themselves, be assigned to a slot in a deeper shadow tree. If this occurs, the elements assigned to the first slot are also treated as being assigned to the deeper slot. The deepest slot that an element is assigned to is its final assigned slot.
Elements assigned to a slot must generate boxes as if they were children of their final assigned slot (rather than children of their actual parent in a shadow host’s light tree).
I think we can remove these sentences. If we use the flat tree in the previous section, we do not need to mention a slot here as a special case.
3.2.2. Selecting Slot-Assigned Content: the ::slotted() pseudo-element
The ::slotted() pseudo-element represents the elements assigned to a slot. This pseudo-element only exists on slots.
"::slotted()" represents "distributed nodes", instead of "assigned nodes".
"assigned nodes" and "distributed nodes" are different.
I think you can refer this as the definition of "distributed".
If the <compound-selector> is omitted, it defaults to the universal selector.
We haven't discussed this in this issue before, and when I implemented in Blink I made the <compound-selector> mandatory, not be omitted. As :host has 2 forms (:host and :host()) and the latter the parameter is not omissible, the difference may be confusing. @tabatkins, can this <compound-selector> be mandatory parameter and author must specify * explicitly if it wants?
@annevk::slotted does not represent anything on its own; it's an aliasing pseudo-element (the first of its kind, I guess) rather than a box-creating pseudo-element. In other words, it functions kinda like a combinator, but with limitations (one compound selector).
I hadn't caught that multiple shadow roots were removed; I'll fix.
For the rest of your comments, I will (a) rephrase the explanatory part to be clearer that I'm not trying to redefine anything from DOM, just provide some framing for everything else in the spec (so people don't have to go read and understand DOM just to understand what I'm talking about), and (b) pull in all the flattening/distributing stuff so you can remove it from Shadow DOM.
Between DOM and CSS Scoping, it looks like nearly all of Shadow DOM is getting eaten by other specs, so we should be able to remove most or all of it soon!
Closing this issue because the behavior is largely defined in the CSS scoping spec. We can file a new issue to track the remaining issues if there are any.
Stop closing this issue, people won't suddenly forget they need this.
?? ::slotted is already supported by all major browser engines as far as I know. If you have specific issues to discuss, file a new issue in CSS scooping spec. There is nothing left to discuss in the broader web components community at the moment.
""::slotted() should full support complex selector"" has came up multiple time and always get closed without any solution.
That should be tracked in a new issue, not in this old issue about ::slotted pseudo element. Also, supporting complex selector inside ::slotted would be about matching selector in the tree in which slotted node appears, not about selecting arbitrary descendant of slotted content. Regardless, you should file a new issue. We can't tack every new idea into an existing issue.
@Lonniebiz I’m not sure this is as arbitrary as it seems at first. If I’ve understood right, the performance cost stems from a mathematical truth rather than browser implementation details. (Correct me if I’m mistaken.)
Activity
JanMiksovsky commentedon Sep 28, 2015
I recently did a search through the Basic Web Components project looking for where we currently use ::content. We concur with Polymer: the only cases where we currently use ::content are trying to style the direct children of an insertion point.
Regarding the name of this selector, it seems that the term "slotted" here is being used as a synonym for "assigned". For consistency with the use of "assigned" in the spec, and with existing API members such as getAssignedNodes(), perhaps this selector could be called ::assigned. That would reduce the number of terms and concepts a developer needs to learn here.
hayatoito commentedon Sep 29, 2015
@JanMiksovsky . Thank you! That's exactly the information I'd like to see.
Regarding the name of this selector, I'm afraid that
::assignedmight be a confusing name.In this example,
https://w3c.github.io/webcomponents/spec/shadow/#composition-example
T::assigned(*)should matchHandP.OandP.rniwa commentedon Sep 29, 2015
Yeah, if we're making this pseudo element flatten slot elements' assigned node lists, then we should probably refrain from using the term "assigned". Also, someone pointed out that "assigned" might sound too generic while "slotted" sounds a lot more related to slot elements.
hayatoito commentedon Oct 1, 2015
We don't need to wait for #308 (comment). The following (tentative) definition could be enough:
A::slotted(simple_selector)matches a node B if and only if:TakayoshiKochi commentedon Dec 14, 2015
Let me confirm:
For Shadow DOM V0, the following pattern is often used:
::content > div { color: blue; }The
color: blueis applied to<div>, not the parenting<content>.(and in the selector matching,
::contentmatches<content>, of course)In the proposed
::slotted()for V1, an author would expect the same as above by:::slotted(div) { color: blue; }If @hayatoito's comment above is adopted, the
color: blueis applied to<div>(which is node B in the comment), not the parenting
<slot>(which is node A).Obviously if an author wants to style
<slot>element itself,it can write
slot { color: blue; }and no fancy pseudo class/element should be required,so the matching logic in the above comment should be correct, but let me confirm.
(I was a bit confused by the name, btw)
hayatoito commentedon Dec 14, 2015
Let me clarify the definition:
A::slotted(simple_selector)matches a node B if and only if:Does it make sense?
TakayoshiKochi commentedon Dec 18, 2015
Thanks, it is clearer now.
Another question: Do we allow
::slottedwithout function-style parameter?In that case, any element slotted under
<slot>would match the rule?In the default slot case, text node could match the rule, then?
E.g.
::slottedwould be almost equivalent to::slotted(*), but if a text node is slotted under a<slot>, it might be different.In shadow's style:
where in this HTML:
TakayoshiKochi commentedon Dec 18, 2015
In my opinion,
::slottedis allowed, but it must be equivalent to*::slotted(*)and it never matchesslotted text node.
hayatoito commentedon Dec 18, 2015
In a general rule, you cannot select text nodes with CSS selector, even with
*. :)hayatoito commentedon Dec 18, 2015
"::slotted"(without parameter) is disallowed. It is invalid as if"div >"is invalid as a selector.hayatoito commentedon Jan 6, 2016
Ops. I meant a "compound selector" here, instead of a "simple selector". The motivation is to disallow "combinator" being used.
Thus, the definition should be:
A::slotted(compound_selector)matches a node B if and only if:e.g.
slot[name="slot1"]::slotted(div.foo)I expect that this does not increase the difficulty of the implementation, however, this gives us much flexibility. :)
hayatoito commentedon Jan 12, 2016
Good question. I've never thought this case. :)
This did not work, as intended, IMO. We might not want to support this because a pseudo element, which "::before" matches, is not a member of a distributed nodes of SLOT. This should not match.
How to support this kind of consecutive pseudo elements is up to each pseudo element. In this case, it's up to "::slotted" pseudo element.
In a general rule, selectors have a limitation about what can be followed after a pseudo element.
I'm +1 not to support this unless we have a strong use case.
I'd like "::slotted" be valid only when it is the last item in a selector, as of now.
24 remaining items
tabatkins commentedon Apr 14, 2016
Right, that's because :host() always represents the host element; it just uses the argument to query the tree to see if it should match or not. Putting ::before inside the argument wouldn't make any sense - you dont' want to check if an ancestor has a ::before pseudo-element.
::slotted, on the other hand, uses its argument to decide which of its assigned slotables it's supposed to represent. As such, it makes a little more sense to have ::before inside.
(At least, it makes as much sense as using doing something like
:matches(.foo, .foo::before), which is allowed.)I don't have a problem with
::slotted(.foo)::before, it just means dealing with chained pseudo-elements. Which we had before, so it's probably not a problem.I'll also note that if you're drawing parallels between
:host()and::slotted(), authors probably will too - they select up and down outside the shadow tree. Having them work as similarly as possible (main difference being the number of colons) is probably good for comprehension. So that's an argument for::slotted()::before.annevk commentedon Apr 15, 2016
It seems weird though since it addresses a box inside
.foo, not inside::slotted.hayatoito commentedon Apr 15, 2016
Thank you, @tabatkins !
I reviewed quickly. Here are my comments:
Since the actual logic, "Which elements generate a box?", should be explained by the concept of the flat tree ,
can we avoid to explain that in details here?
I'm wondering how to state it simply in css scoping. The current Shadow DOM spec has the followings in the section of Flat trees:
I think we should upstream these sentences to CSS scoping. I guess these sentences need to be refined somehow to match the css scoping world.
DOM Standard does not need a flat tree. I think only css scoping is a client of a flat tree. Thus, eventually, we need to upstream a flat tree to CSS.
3.1. Shadow DOM Selection Model
This can be:
Yeah, multiple shadow trees are removed.
Otherwise, we might want to omit this because it looks a duplication of the HTML Standard.
3.1.1. Shadow Hosts in a Shadow Tree
This can be:
because multiple shadow trees are removed.
3.1.2. Slots and Slotted Elements in a Shadow Tree
I think we can remove these sentences. If we use the flat tree in the previous section, we do not need to mention a slot here as a special case.
3.2.2. Selecting Slot-Assigned Content: the ::slotted() pseudo-element
"::slotted()" represents "distributed nodes", instead of "assigned nodes".
"assigned nodes" and "distributed nodes" are different.
I think you can refer this as the definition of "distributed".
TakayoshiKochi commentedon Apr 15, 2016
In 3.2.2,
We haven't discussed this in this issue before, and when I implemented in Blink I made the
<compound-selector>mandatory, not be omitted. As:hosthas 2 forms (:hostand:host()) and the latter the parameter is not omissible, the difference may be confusing.@tabatkins, can this
<compound-selector>be mandatory parameter and author must specify*explicitly if it wants?tabatkins commentedon Apr 15, 2016
@annevk
::slotteddoes not represent anything on its own; it's an aliasing pseudo-element (the first of its kind, I guess) rather than a box-creating pseudo-element. In other words, it functions kinda like a combinator, but with limitations (one compound selector).@TakayoshiKochi Yeah, I can make the argument mandatory.
@hayatoito Thanks for the review!
I hadn't caught that multiple shadow roots were removed; I'll fix.
For the rest of your comments, I will (a) rephrase the explanatory part to be clearer that I'm not trying to redefine anything from DOM, just provide some framing for everything else in the spec (so people don't have to go read and understand DOM just to understand what I'm talking about), and (b) pull in all the flattening/distributing stuff so you can remove it from Shadow DOM.
Between DOM and CSS Scoping, it looks like nearly all of Shadow DOM is getting eaten by other specs, so we should be able to remove most or all of it soon!
tabatkins commentedon Apr 21, 2016
I've finished all the edits; they ended up necessitating a larger reorg/rewrite than I'd expected! Scoping now defines the flattened tree, too.
rniwa commentedon May 5, 2016
Closing this issue because the behavior is largely defined in the CSS scoping spec. We can file a new issue to track the remaining issues if there are any.
rniwa commentedon May 22, 2020
??
::slottedis already supported by all major browser engines as far as I know. If you have specific issues to discuss, file a new issue in CSS scooping spec. There is nothing left to discuss in the broader web components community at the moment.rniwa commentedon May 22, 2020
That should be tracked in a new issue, not in this old issue about
::slottedpseudo element. Also, supporting complex selector inside::slottedwould be about matching selector in the tree in which slotted node appears, not about selecting arbitrary descendant of slotted content. Regardless, you should file a new issue. We can't tack every new idea into an existing issue.Lonniebiz commentedon Oct 7, 2020
What a disappointing arbitrary limitation. Let the browser-makers solve performance issues and write the spec to be ideal. WEAK!
bathos commentedon Oct 7, 2020
@Lonniebiz I’m not sure this is as arbitrary as it seems at first. If I’ve understood right, the performance cost stems from a mathematical truth rather than browser implementation details. (Correct me if I’m mistaken.)