const MyElement = customElement((params) => {
const {
internals,
elementRef,
root,
connectedCallback,
} = params;
internals.role = 'button';
connectedCallback(() => {
console.log(elementRef.querySelector('a[href]')); // light DOM
console.log(root.querySelector('a[href]')); // shadow DOM
});
// ...
});
attachShadow() shadowRootOptions
const MyElement = customElement(() => {
// ...
}, { shadowRootOptions: { delegatesFocus: true } });
false attachShadow root
const MyElement = customElement(() => {
// ...
}, { attachShadow: false });
<slot> innerHTML
const MyElement = customElement(({ root }) => {
return html`
<button class="primary">
${root.innerHTML}
</button>
`;
}, { attachShadow: false });