Class Slot<T extends Slot<T>>


public class Slot<T extends Slot<T>> extends StyledContainerElement<T>
Represents an HTML <slot> element for web component content distribution.

The <slot> element is a placeholder inside a web component's shadow DOM that can be filled with content from the light DOM. Named slots allow multiple insertion points, while an unnamed (default) slot captures any content not assigned to a named slot. Slots are a core part of the Web Components specification and enable flexible, composable custom elements.

Features:

  • Defines insertion points in shadow DOM
  • Supports named slots for targeted content distribution
  • Default (unnamed) slot captures unassigned content
  • Can contain fallback content displayed when no content is assigned
  • Works with the slot attribute on light DOM elements

Usage:


 // Default slot (captures unassigned content)
 Slot defaultSlot = new Slot();
 defaultSlot.addElement(new P("Default fallback content"));

 // Named slot for specific content
 Slot headerSlot = new Slot("header");
 headerSlot.addElement(new H3("Default Header"));

 // Named slot for footer
 Slot footerSlot = new Slot("footer");
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • invalid reference
    StyledElement
  • Template
  • Constructor Details

    • Slot

      public Slot()
      Constructs an unnamed (default) <slot> element.

      The default slot captures any light DOM content not assigned to a named slot.

    • Slot

      public Slot(String name)
      Constructs a named <slot> element.

      A named slot captures light DOM elements that have a matching slot attribute.

      Parameters:
      name - the slot name; light DOM elements with slot="name" will be distributed here
  • Method Details

    • setName

      public final T setName(String name)
      Sets the name of this slot.

      Light DOM elements with a matching slot attribute will be distributed to this slot.

      Parameters:
      name - the slot name