-
Notifications
You must be signed in to change notification settings - Fork 666
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
[css-scoping-1] add :has-slotted() pseudo class #10586
Open
keithamus
wants to merge
2
commits into
w3c:main
Choose a base branch
from
keithamus:add-has-slotted-psuedo-class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,44 @@ Selecting Slot-Assigned Content: the ''::slotted()'' pseudo-element</h4> | |
The only way to style assigned text nodes | ||
is by styling the <a>slot</a> and relying on inheritance. | ||
|
||
<h4 id='has-slotted-pseudo'> | ||
Matching Selectors Against Slot-Assigned Content: the '':has-slotted()'' pseudo-class</h4> | ||
|
||
The <dfn selector>:has-slotted()</dfn> pseudo-class, when evaluated | ||
<a>in the context of a shadow tree</a>, | ||
matches the <a>slot</a>, if one of its | ||
<a lt="find flattened slottables">assigned elements, after flattening,</a> matches the provided <<compound-selector>>. | ||
In any other context, it matches nothing. This pseudo-class only exists on <a>slots</a>. | ||
|
||
The [=specificity=] of '':has-slotted()'' is that of a pseudo-class, | ||
plus the [=specificity=] of its argument. | ||
|
||
The grammar of the '':has-slotted()'' pseudo-element is: | ||
|
||
<pre class=prod>:has-slotted( <<compound-selector>> )</pre> | ||
|
||
<div class="example"> | ||
For example, say you had a component with both children and a shadow tree, | ||
like the following: | ||
|
||
<pre> | ||
<x-foo> | ||
<div id="one" slot="foo" class="foo">...</div> | ||
<"shadow tree"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to use the |
||
<slot id="theslot" name="foo"></slot> | ||
</"shadow tree"> | ||
</x-foo> | ||
</pre> | ||
|
||
For a stylesheet within the <a>shadow tree</a>, | ||
selectors like '':has-slotted(*)'', '':has-slotted(div)'', '':has-slotted(.foo)'', and '':has-slotted(#one)'' | ||
will match ''#theslot'', while '':has-slotted(p)'', '':has-slotted(:not(.foo))'', '':has-slotted(#two)'' | ||
will not. | ||
</div> | ||
|
||
Note: '':has-slotted()'' will only match the ''slot'' element, not the contents. Slotted contents | ||
can be matched with the ''::slotted()'' pseudo-element. | ||
|
||
<!-- | ||
██████ ███ ██████ ██████ ███ ████████ ████████ | ||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | ||
|
@@ -613,7 +651,7 @@ Name-Defining Constructs and Inheritance</h3> | |
|
||
For example, | ||
given the following document | ||
(using the imaginary <::shadow></::shadow> markup | ||
(using the imaginary ''<::shadow></::shadow>'' markup | ||
to indicate an element's [=shadow tree=]): | ||
|
||
<xmp highlight=markup> | ||
|
@@ -733,7 +771,7 @@ Serialized Tree-Scoped References</h4> | |
|
||
For example, | ||
given the following document | ||
(using the imaginary <::shadow></::shadow> markup | ||
(using the imaginary ''<::shadow></::shadow>'' markup | ||
to indicate an element's [=shadow tree=]): | ||
|
||
<xmp highlight=markup> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"after flattening" is interesting here because it give "non-slotted" content while being required to gather all slotted content. E.G.:
In the example above "Test" will display red in the case that flattened elements are leveraged.
However, if you don't use flattened elements:
This "Test" will also be red. And, without flattened elements,
This "Test" will also be red.
I'm not sure it's a real thing, but is there a place between
::slotted(*)
and.assignedElements({flatten: true})
that would resolve the external assigned to a slot and not the default ones internal to the shadow host?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, I think it's important that
:has-slotted
matches using the same rules for matchable elements as::slotted
.Concretely, since
::slotted()
never matches either<slot>
or fallback content,:has-slotted
also should not match when it would by selecting either<slot>
or fallback content.See #5482. IMO, the spec is still very confusing and possibly indicates that this should match, but the CSS working group resolved that the current behavior is intended in #5482.
I think matching against fallback content both for
::slotted
and:has-slotted
is valuable, but I suggest it should be tackled as a follow-on to this feature.