Going through the Shadow DOM (v1) example in this tutorial, it defines a Web Component (tabs), wherein each Tab corresponds to a named and default slot:
<fancy-tabs>
<button slot="title">Title</button>
<button slot="title" selected>Title 2</button>
<button slot="title">Title 3</button>
<section>content panel 1</section>
<section>content panel 2</section>
<section>content panel 3</section>
</fancy-tabs>
And it would render to this:
<fancy-tabs>
#shadow-root
<div id="tabs">
<slot id="tabsSlot" name="title">
<button slot="title">Title</button>
<button slot="title" selected>Title 2</button>
<button slot="title">Title 3</button>
</slot>
</div>
<div id="panels">
<slot id="panelsSlot">
<section>content panel 1</section>
<section>content panel 2</section>
<section>content panel 3</section>
</slot>
</div>
</fancy-tabs>
In order to preserve an existing API, I'd like to create a component similar to this, but one where I can create each Tab as its own Custom Element. So an API that looks like:
<fancy-tabs>
<fancy-tab>
<button slot="title">Title</button>
<section>content panel 1</section>
</fancy-tab>
<fancy-tab>
<button slot="title" selected>Title 2</button>
<section>content panel 2</section>
<fancy-tab>
<fancy-tab>
<button slot="title" selected>Title 3</button>
<section>content panel 3</section>
<fancy-tab>
</fancy-tabs>
But have it render to similar Shadow DOM as above.
In other words, what I'd like is to have is an intermediate element like <fancy-tab>
, while still controlling the slot elements below it. I've tried creating <fancy-tab>
as a CE with an open shadowRoot, as a CE with no shadowRoot, and not defining it as a custom element at all.
Is there a way to do this? Or do slots have to be at the first child of the Light DOM?