Using the web components specification, is it possible to extend a specific type of <input>
element?
This question is similar to mine, but it only specifies how to extend a button
element, not a text input or any other variant of the <input>
tag.
In my case, I'd love to extend a checkbox (<input type="checkbox" />
) or a radio button (<input type="radio" />
) in order to wrap more complex UI around the same core input element functionality, but I don't see any way to do that using the extends
syntax provided by document.registerElement
. In my mind it would seem that you should be able to do something like the following:
document.registerElement('x-checkbox', {
prototype: Object.create(HTMLInputElement.prototype),
extends: 'input[type=checkbox]'
});
However, this specific case doesn't seem to be documented or explained anywhere that I can find, and I'm fairly confident that example won't work in practice.
setAttribute('type', 'checkbox')
on the HTMLInputElement object before setting it as theprototype
. – Foraminifertype
attribute alone would solve that. – Wheenis
attribute. Wasn't thinking about that. You may be on to something there. – Wheenis
must be used if you are extending another standard HTML element. Since there is nocheckbox
element, you cannot extend things likeinput[type=checkbox]
or radio. Extend the whole input element and specify the type. – Concordat