-
Notifications
You must be signed in to change notification settings - Fork 641
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
[selectors] Should :not(foo) match the host of the shadow tree? #10179
Comments
An author reason for not matching the host with Say I want to style :not(.foo) img { ... } If I would instead have to write: :host :not(.foo) img { ... } or add some other selector outside |
Yeah that's a really good point. |
I think it’s important to preserve the expectation that The |
Well, * wouldn't match the host. |
Consider Logically it can be a bit strange if I think the possibilities are:
|
I think there might be a third option which even though it's a bit weird would be an improvement on (1) if we go that route, which is conditioning matching it on the selector having a :host selector in some way (which was my read of the spec). Depending on how we define that, it could make |
This has some pitfalls, though: The mere presence of :host would influence the rest of the selector. We probably don't want this situation:
Not to mention the forward-compat issues we had with nesting, where people were worried about what would happen if something unknown to the browser (from a future spec) was nest-containing. You have a similar problem here with “host-containing”. TBH I'm not too worried about performance here; it's just one more element to match in a potentially very long chain, and if you want to optimize that out by checking for |
Not necessarily, right? The |
So if I understand correctly, your proposal would be that a selector needs to fall into one of these cases:
Then, for simple selectors:
For selector lists: same as I'm less sure about compound and complex selectors:
|
Whoops, sorry for missing this! For the general behavior, @lilles got it exactly right - the point of featurless-ness is to make it so that authors don't have to think about the host elements most of the time and will still get the likely intended behavior, so (In other words, Lea's request that For the more complex cases, I hadn't actually thought thru those cases when writing up the feature, but I think @Loirooriol's breakdown works well. For the more complex :not() cases, I think we might want to add the following:
This would make both of the complex :not() cases "not allowed to match the host". |
#9509 clarified that stuff like
:is(:host)
should definitely match, due to text in https://drafts.csswg.org/selectors/#data-model:So after discussing a bit with @sesse, it wasn't super-clear to me what the expected behavior is for something like this:
I could see arguments for both behaviors:
:host
selector at all to match that host.span
nor:not(span)
match.My read of the spec is that
:not(span)
should not match, because that selector is not "a logical combination pseudo-class representing those selectors [:host
for simplicity]".I think that's my preferred behavior too, because that makes it simpler to determine "can this selector match the host" (we optimize stylesheets in shadow trees to not match a lot of the rules from the host). But ultimately I could go either way I guess.
My read of the spec doesn't match @sesse, and it seems at least the spec could get a clarification of what that "representing those selectors" means. Maybe "containing those selectors", if my read is correct, or just removing that text, if @sesse's is?
cc @tabatkins @rniwa
The text was updated successfully, but these errors were encountered: