-
Notifications
You must be signed in to change notification settings - Fork 715
:predefined
pseudo-class for built-ins (i.e. not custom elements)
#11001
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
Comments
Then to match defined custom elements, you'd need |
Unfortunately, customized built-ins still exist despite Webkit not supporting them, so they probably need to be accounted for here:
Presumably then via this proposal:
|
Expanding the use case (from #11140) by @KonnorRogers... ProposalAdd a selector to only target built in elements. Why?with custom elements being more and more prevalent, it's sometimes important to separate custom elements from built in elements, especially with things like CSS resets. common scenario in a CSS reset such as Tailwind: * {
border: 0;
} but this can mess up custom elements that use a with a pseudo selector like :builtin {
border: 0;
} other scenarios:
:builtin:invalid {
outline: 2px solid red;
}
:not(:builtin) {
display: contents;
} issues with
|
Something in this area would be a nice win. Whether Small bit of bikeshedding: |
FWIW,
So for example, if I had The "easy" way to check custom elements from JS is to do: /* pseudo code for tag selecting */
*-* {
} |
Really great point and definitely belies an assumption on my past as to why “a framework author who said they use a different code path when the template contains custom elements” might want this feature. Hopefully we can get people representing this need involved in the conversation! |
Thanks for liking me the issue. What we want is The CSS selector, would be nice I guess, but when you are in a hot path, you do not want to query-selector/match anything at all, you just want to know if a given element is a web-element or not. |
Correct. Nothing is stopping someone from doing:
this issue tracker is about CSS though. I imagine this probably isn't the place to talk about |
Right, its kind of relevant because we want the same thing but as a property instead. |
It is currently impossible to match custom elements generically.
:not(:defined)
matches custom elements that have not yet been defined, but since:defined
also matches built-ins, there is no way to target all custom elements.Admittedly the use cases for this are niche (it came up in a Twitter discussion with a framework author who said they use a different code path when the template contains custom elements), but also it’s a pretty simple addition, so why not.
We could introduce a
:predefined
pseudo-class to match native elements, authors can simply use:not(:predefined)
to match custom elements. Or we could introduce a pseudo-class to directly match custom elements, though I have no idea what to call it 🙃(Ideally we should eventually introduce more granular selectors to target element by tag prefix and/or suffix but this is a nice quick fix that can be implemented pretty easily, and is useful in its own right.)
The text was updated successfully, but these errors were encountered: