I'm trying to extend the HTMLOptionElement
,
<template id="cOptionTemplate">
<content></content>
</template>
<select>
<option is="custom-option">Test</option>
</select>
var cOption = document.registerElement('custom-option', {
prototype: Object.create(HTMLOptionElement.prototype, {
createdCallback: {
value: function() {
var template = document.getElementById("cOptionTemplate")
var clone = document.importNode(template.content, true);
this.createShadowRoot().appendChild(clone);
}
},
attributeChangedCallback: {
value: function (attrName, oldVal, newVal){
switch(attrName){
case "attr1":
console.log(this);
}
}
}
}),
extends: "option"
});
Here's a demo of the code.
but apparently that doesn't work because it already has a user agent shadowRoot?
Uncaught InvalidStateError: Failed to execute 'createShadowRoot' on 'Element': Shadow root cannot be created on a host which already hosts an user-agent shadow tree.
I have never seen this error and I thought it lets you attach multiple shadow roots. Why is it happening and is there a way to make it work?