No, because then the user of the custom element has to put slot attributes on the things they put in the tabs. Consider this:
<tab-area>
<tab- text='First'>
...arbitrary HTML that should work intuitively, i.e. be styled
like the rest of the document.
</tab->
<tab- text='Second'>
Note the lack of slot attributes on these tab elements. That's
because we want this to behave like normal HTML where you
can nest without having to worry about how tab-area was implemented.
Why should we have to care that tab-area was implemented with
templates/slots?
</tab->
<tab- text='Third'>
There could be any number of these tabs so you can't put them
into slots without some sort of late-generating the slots anyway.
</tab->
</tab-area>
We want this to render like a group of tabs where "First" and its body are visible, and tabs are peeking up from behind with the texts "Second" and "Third" but the content of those tabs isn't shown until you click the tab (at which point the content of "First" is hidden).
That's not achievable with slots.
In general, I haven't found a case where templates/slots are actually useful--it's a lot of work to create a bad interface.
Most of the time you have the tab and the panel to display the content of the tab a super simple demo implementation of something like this https://web.dev/components-howto-tabs/
In regards of slots, they are a nice way to allow a user of you webcomponent to overwrite/replace parts of your component with something else. This is most of the time a more advanced feature and I find it quite nice to build headless components
> Most of the time you have the tab and the panel to display the content of the tab a super simple demo implementation of something like this https://web.dev/components-howto-tabs/
That's exactly what I'm saying is bad. Why does the user of the howto-tabs have to type "slot='panel'" when that information is already communicated by the fact that it's a "howto-panel" inside a "howto-tabs"? This is a useless leaking of implementation details.
And that page just keeps going and going. Sure, some of that is because they're implementing a few neat features, but most of it is because slots are way overcomplicated for something that's actually easier to do without them.
you can just have an unnamed slot. I'm probably missing something here haven't build a tabs thing in a long time. But just trying this out for a couple of minutes the thing you want seems to be possible. I didn't do any styling here and the code is just something I hacked down to test it. Where hn-tabs is your tab-area and hn-tab your tab-
When I have some time I'll play around with this: I'm certainly open to the idea that there's some stuff I don't know about slots. But I have a question: When you append the slot to the shadow root, doesn't that mean that you lose styling in the slot contents?
That's not achievable with slots.
In general, I haven't found a case where templates/slots are actually useful--it's a lot of work to create a bad interface.