How do slots work in light DOM components? #1019
-
|
WebJs components render light DOM by default. How does slotting work there, since native Is there full API parity with shadow DOM slots (named slots, fallback content, slot assignment)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Native
class Panel extends WebComponent({}) {
render() {
return html`
<header><slot name="header"></slot></header>
<main><slot></slot></main>
<footer><slot name="footer">no actions</slot></footer>`;
}
}
Panel.register('my-panel');<my-panel>
<h2 slot="header">Title</h2>
<p>Body goes in the default slot.</p>
</my-panel>The DOM API mirrors shadow slots too, so imperative code ports without changes: On the SSR question, both modes render slotted content on the server, so it's there with no JS. Light DOM projects the assigned children into the slot at SSR (you'll see a The one thing that is genuinely shadow-only is the |
Beta Was this translation helpful? Give feedback.
<slot>works exactly the same in light DOM as it does in shadow DOM, and there is deliberate API parity between the two. You write the same template, and moving a component between modes never requires a rewrite.Native
<slot>is a shadow-DOM primitive, so in light DOM WebJs implements slotting itself, but it does so to spec rather than approximating it. Everything you'd expect from shadow slots is there:name=${...}