-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
custom name of a customized built-in element is unreachable #4043
Comments
I proposed this in #3402 (comment) but we didn't have a concrete use case then. cc @whatwg/components |
Read through the thread, having |
I just found this issue and asymmetry with the "is" content attribute. It causes issues when trying to use selectors. See this simple example (taken from actual production code) - the desire is to be able to style (from light DOM) elements of the customized type only: <style>
p[is="my-p"] { background-color: green; }
p:not([is="my-p"]) { background-color: red; }
</style>
<p is="my-p">This retains the "is" attribute</p>
<script>
customElements.define('my-p',class extends HTMLParagraphElement {}, {extends: 'p'});
const foo = document.createElement('p', {is:'my-p'});
foo.appendChild(document.createTextNode('This does NOT retain the "is" attribute'));
document.body.appendChild(foo);
</script> Is there a recommended better way to do this? It can obviously be overcome pretty easily like this: const foo = document.createElement('p', {is:'my-p'});
foo.setAttribute('is', 'my-p'); but that seems very hacky, given the declarative version doesn't need this, and the imperative version serializes as |
There's not I think, but with Safari not willing to add |
I must say that since that time as till now I've completely abandoned support for a customized built-ins due to both, a seemingly not-yet-well-baked spec as well as quite a strong objection of WebKit guys to provide that part. |
Use-case:
Framework working on DOM elements needs to process undefined custom elements only when defined.
For the regular custom element it is simple:
But for customized built-in element this is not possible, since
element.localName
is just a standard DOM element's name and there is no way right now to reach the extended name provided inis
property:BTW, when the same element is being added as below,
is
handled as an attribute and is reachable:Proposal:
is
value as an attribute in a symmetric toHTML
ish syntax. As proposed by someone (see refs below) it should probably be readonly IDL attributeis
to be the same either provided fromcreateElement
JS API or coming from HTML's attributeAppendix:
The text was updated successfully, but these errors were encountered: