I am new to web components. Since v1 web components are available, I start there. I read various posts on the Internet about them. I am especially interested in compiling them correctly. I read about the slots and made them work, although my efforts did not result in the use of slot web components that work as I expected.
If I have nested web components like this, the DOM from the nested / slot web component is not inserted into the parent slot:
<parent-component> <child-component slot="child"></child-component> </parent-component>
And here is the parent HTML web component:
<div id="civ"> <style> </style> <slot id="slot1" name="child"></slot> </div>
Since each web component (parent and child) is written as independent, I created them using
customElements.define('component-name', class extends HTMLElement { constructor() { super(); this.shadowRoot = this.attachShadow({mode: 'open'}); this.shadowRoot.innterHTML = `HTML markup` } })
As a result, the DOM contains 2 shadow roots. I tried to write child / slot elements without shadow dom, which also does not cause the parent shadow house to place child elements.
So, what is the correct way to build v1-nested web components?
source share