-
Notifications
You must be signed in to change notification settings - Fork 32
No "backwards compatible" way to match custom states on shadow parts #62
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
I wonder if the overhead (both in terms of bundle size and watchers) is worth the payoff. Unfortunately custom states can’t quite be polyfilled fully because CSS won’t parse rules it doesn’t recognize. Is there a reason you couldn’t do |
How about only adding For example, with the following shadow tree: <c-e-inner part="inner"></c-e-inner>
<c-e-inner></c-e-inner> and both elements having state c-e::part(inner):--foo { /* using native support */ }
c-e::part(inner state--foo) { /* using the polyfill */ } |
The library somehow emulates custom states through attributes so they can be matched in CSS when the polyfill is used. Unfortunately this won't allow matching the custom states when the element is exposed as a shadow part, as
::part()
can only be followed by a non-structural state selector or pseudo-element selector.For instance, given a custom element
c-e-inner
with custom state--c-s
and another custom elementc-e
whose shadow tree looks like:In browsers supporting custom states, you can match it using the following selector:
But
c-e::part(inner)[state--c-s]
is illegal and thus won't work in browsers not supporting custom states.Proposal: expose custom states on shadow parts using other shadow parts.
Specifically, with the above example, make it work with the following selectors:
In terms of implementation, whenever a custom state is added/deleted, if the element as a non-empty
part
DOMTokenList (ignoring any parts added to emulate the custom states), then add/delete as many corresponding parts whose name is composed as${part}--state--${state}
. This conversely mean observing attribute mutations to detectpart=""
changes so that whenever an element gains/loses a part, the corresponding parts added by the polyfill are added/deleted accordingly, all while trying to avoid an infinite recursion. (I would probably try to implement this by getting all non-state-related parts and ensuring that all the corresponding state-emulating parts are present, and to properly handle a removedpart
name then either make sure all state-emulating part matches a non-state-related part, or parse the attribute's old value to determine which parts were removed if any)Elements using
exportparts
would have to manually export all possible parts, renaming them if needed:The text was updated successfully, but these errors were encountered: