if those descendants include a <slot> element, then the regular light DOM children of the host element are displayed as if they were children of that <slot>(they do not actually become part of the shadow DOM), replacing any shadow DOM content in the slot.
if shadow DOMdoes not include a <slot>, then any light DOM content of the host is never displayed.
if shadow DOM has a <slot>, but the shadow host has nolight DOM children, then the shadow DOM content of the slot is displayed as a default.
if shadow DOM defines more than one and names those slots with a name attribute, then children of the shadow host can specify which slot they would like to appear in by specifying a slot="slotname" attribute.
if we put something inside <slot>(in shadow DOM), it becomes the fallback content, browser shows it if thereโs no corresponding element in light DOM.
๐ See tab 2๏ธโฃ below.
Default Slot
The first unnamed<slot> in shadow DOM is a โdefault slot". It gets all nodes from the light DOM that arenโt slotted elsewhere. ๐ See tab 1๏ธโฃ below.
Code Example
<user-card>
<!-- โญ๏ธ light DOM: slotted elements -->
<!-- โญ๏ธ only top-level children may have [slot="โฆ"] attributeโ๏ธ -->
<span slot="username">John Smith</span>
<span slot="birthday">2001.01.01</span>
</user-card>
for each<slot name="X"> in shadow DOM, the browser looks for[slot="X"] in the light DOM and insert it into the slot, the result is called flattened DOM.
๐ See code in "shadow DOM", "flattened DOM" tabs above.
if there are multiple elements in light DOM with the same[slot="X"], they are appended into the same<slot name="X"> (in shadow DOM), one after another.
Flattened DOM
the flattened DOM exists only for rendering and event-handling purposes. Itโs kind of โvirtualโ. Thatโs how things are shown. But the nodes in the document are actually notmoved around! ๐ See "flattened DOM" tab above.
The process of rendering slotted elements inside their slots is called โcompositionโ.