-
Notifications
You must be signed in to change notification settings - Fork 665
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
base: main
Are you sure you want to change the base?
Conversation
css-scoping-1/Overview.bs
Outdated
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, after flattening,</a> matches the provided <<compound-selector>>. |
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.
"if one of its assigned, after flattening, matches "
Is there a missing word there? "child elements"?
<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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to use the <::shadow>
markup here?
Exciting start! Points to the need for If you haven't already, I think I might take a pass some tentative WPTs based on this outline during the week of the 12th. |
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>>. |
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.:
<div>
<template shadowrootmode="open">
<style>
div {
color: green;
}
:has-slotted(div) {
color: red;
}
</style>
<slot><div>Test</div></slot>
</template>
</div>
In the example above "Test" will display red in the case that flattened elements are leveraged.
However, if you don't use flattened elements:
<div>
<template shadowrootmode="open">
<div>
<template shadowrootmode="open">
<style>
div {
color: green;
}
:has-slotted(div) {
color: red;
}
</style>
<slot></slot>
</template>
<slot><div>Test</div></slot>
</div>
</template>
</div>
This "Test" will also be red. And, without flattened elements,
<div>
<template shadowrootmode="open">
<div>
<template shadowrootmode="open">
<style>
div {
color: green;
}
:has-slotted(div) {
color: red;
}
</style>
<slot></slot>
</template>
<div>Test</div>
</div>
</template>
</div>
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.
@keithamus could you please rebase to resolve conflicts? Also, I wonder if it may be better to do this in two steps: get the non-functional form in first ( Looking at the resolution it is unclear if it even allows for a functional form, given the original proposal was for a non-functional form. In fact, the non-functional form is not simply an alias for |
* Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint
…only Automatic update from web-platform-tests Speculativly test :has-slotted() (#47587) * Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint -- wpt-commits: 43f3ba0919b8e4adf07bc9f0620b14d113a1abb6 wpt-pr: 47587
…only Automatic update from web-platform-tests Speculativly test :has-slotted() (#47587) * Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint -- wpt-commits: 43f3ba0919b8e4adf07bc9f0620b14d113a1abb6 wpt-pr: 47587 UltraBlame original commit: 33299c67798ea323257a0ce9f05a6593df343457
…only Automatic update from web-platform-tests Speculativly test :has-slotted() (#47587) * Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint -- wpt-commits: 43f3ba0919b8e4adf07bc9f0620b14d113a1abb6 wpt-pr: 47587 UltraBlame original commit: 33299c67798ea323257a0ce9f05a6593df343457
…only Automatic update from web-platform-tests Speculativly test :has-slotted() (#47587) * Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint -- wpt-commits: 43f3ba0919b8e4adf07bc9f0620b14d113a1abb6 wpt-pr: 47587 UltraBlame original commit: 33299c67798ea323257a0ce9f05a6593df343457
…only Automatic update from web-platform-tests Speculativly test :has-slotted() (#47587) * Speculativly test :has-slotted(), see: w3c/csswg-drafts#10586 * Speculatively test :has-slotted() flattened through multiple slot elements * Lint -- wpt-commits: 43f3ba0919b8e4adf07bc9f0620b14d113a1abb6 wpt-pr: 47587
Based on the discussion in #6867, and the conclusions within, I thought I'd have a go at specifying a
:has-slotted( <<compound-selector>> )
pseudo class.I put this in
css-scoping-1
; the resolution was to add it incss-selectors-5
but I thought it might be useful living next to:host
,:host()
,:host-context()
and::slotted()
. I am of course happy to move it if folks disagree with this choice.My intent for this PR is largely to present something worthy of discussion. I hope I've achieved that, apologies if this PR amounts to just noise.