-
Notifications
You must be signed in to change notification settings - Fork 313
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
add support for :scope
as a pseudo-class for querySelector[All] / matches / closest
#578
base: master
Are you sure you want to change the base?
Conversation
…atches / closest
Hey, and thanks a lot for the contribution. I haven't really looked at this pseudo class selector before. Looks handy when using query selectors, especially a bit complex ones. I am a bit worried about how invasive this is code-wise. That's not great for maintenance and refactoring. I wonder if there is some way we could improve that? I understand that this selector can only be used once in a query, maybe something we could take advantage of, also performance-wise. How does this selector behave when used in descendant elements? We should have some test cases for that. What happens when using the selector in RCSS? |
It's a staple of modern web development; its main use is to be able to use This was the least invasive way I had found to implement it; it only requires tracking a scope down to the querying function. I'm not sure where else it could go, and I didn't really want to modify all of the types involved just to store a single field on them. My first iteration tried to shove an element reference in We don't have
I've never seen that used in the wild though, heh. The selector can appear more than once in a query, but it always refers to the same element. When used in RCSS, |
Converting to draft for now as I won't have time for a while to poke these. |
Okay, I'm back with this one - I wasn't sure of any alternative approaches for implementation, though, and I'm down to discuss any ideas on how to better approach it. It's been super useful in our own development to speed up matching direct descendent children elements. |
:scope
is a super useful tool in modern web dev, and it's hard to live without it once you're used to using it. This PR adds support for:scope
in its most useful context: used as a scope limiter in Element-based selector functions.This PR only covers the code-side use of :scope; :scope in an RCSS file will do nothing. I don't believe it's useful at all in RCSS without support for
@scope
or:root
, so I didn't bother with those.All of the use-cases here should apply & work: https://developer.mozilla.org/en-US/docs/Web/CSS/:scope#using_scope_in_javascript