Skip to content
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

Support for the new :state() syntax #126

Open
KonnorRogers opened this issue Feb 26, 2024 · 1 comment
Open

Support for the new :state() syntax #126

KonnorRogers opened this issue Feb 26, 2024 · 1 comment

Comments

@KonnorRogers
Copy link

KonnorRogers commented Feb 26, 2024

With the deprecation of the :--state syntax, I imagine the restrictions around requiring the -- prefix should be removed.

https://groups.google.com/a/chromium.org/g/blink-dev/c/GDmNaxAuCY4/m/WOQD5uRTAQAJ

https://html.spec.whatwg.org/multipage/custom-elements.html#exposing-custom-element-states

It has not been implemented in Chrome yet, but it has been implemented in Safari TP and I believe is being worked on for Firefox.

if (!/^--/.test(state) || typeof state !== 'string') {
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${state} must start with '--'.`);
}

https://codepen.io/dannymoerkerke/pen/KKEyarg

^ Example supporting both syntaxes.

@keithamus
Copy link

keithamus commented Feb 26, 2024

https://github.com/keithamus/fdgt/blob/main/stateset.js here's a polyfill I use (gets added here) which uses an internal Set to keep track for unsupported browsers, and calls .add in a try/catch (the current standard doesn't validate beyond the first arg being a string so thrown errors would only be from "old" Chrome). Feel free to repurpose as you see fit for this polyfill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants