확장 내가 확장하는 노력하고있어 HTMLOptionElement
, <option>
<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"
});
여기에 코드의 a demo의
.하지만 이미 사용자 에이전트 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.
나는이 오류를 본 적이 없으며 여러 그림자 뿌리를 첨부 할 수 있다고 생각했습니다. 왜 그런 일이 일어나고 그것을 작동시키는 방법이 있습니까?
많은 기본 요소에 고유 한 사용자 에이전트 섀도우 DOM이 있으므로 사용자 정의 요소에 새로운 섀도우 DOM 만 연결할 수 있습니까? –
예 : 불행히도 :(https://github.com/w3c/webcomponents/issues/110 및/102에서 – Supersharp
워킹 그룹에 의해 논의되었습니다. 어쨌든 고마워요 –