Class SlotUtils

java.lang.Object
com.vaadin.flow.component.shared.SlotUtils

public class SlotUtils extends Object
Util methods for handling child elements inside slots.
Author:
Vaadin Ltd
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addToSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.component.Component... components)
    Adds components to the specified slot in the parent component.
    static void
    addToSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.dom.Element... elements)
    Adds elements to the specified slot in the parent component.
    static void
    clearSlot(com.vaadin.flow.component.HasElement parent, String slot)
    Removes every child element of the parent that are in the specified slot.
    static com.vaadin.flow.component.Component
    getChildInSlot(com.vaadin.flow.component.HasElement parent, String slot)
    Gets the first child component of the parent that is in the specified slot.
    static Stream<com.vaadin.flow.dom.Element>
    getElementsInSlot(com.vaadin.flow.component.HasElement parent, String slot)
    Gets all the child elements of the parent that are in the specified slot.
    static void
    setSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.component.Component... components)
    Clears the specific slot in the parent component and adds components to it.
    static void
    setSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.dom.Element... elements)
    Clears the specific slot in the parent component and adds elements to it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SlotUtils

      public SlotUtils()
  • Method Details

    • getElementsInSlot

      public static Stream<com.vaadin.flow.dom.Element> getElementsInSlot(com.vaadin.flow.component.HasElement parent, String slot)
      Gets all the child elements of the parent that are in the specified slot.
      Parameters:
      parent - the component to get children from, not null
      slot - the name of the slot inside the parent, not null
      Returns:
      the child elements of the parent that are inside the slot
    • clearSlot

      public static void clearSlot(com.vaadin.flow.component.HasElement parent, String slot)
      Removes every child element of the parent that are in the specified slot.
      Parameters:
      parent - the component whose slot to clear
      slot - the name of the slot to clear
    • getChildInSlot

      public static com.vaadin.flow.component.Component getChildInSlot(com.vaadin.flow.component.HasElement parent, String slot)
      Gets the first child component of the parent that is in the specified slot.
      Parameters:
      parent - the component to get child from, not null
      slot - the name of the slot inside the parent, not null
      Returns:
      a child component of the parent in the specified slot, or null if none is found
    • addToSlot

      public static void addToSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.component.Component... components)
      Adds components to the specified slot in the parent component.
      Parameters:
      parent - the parent component to add the components to, not null
      slot - the name of the slot inside the parent, not null
      components - components to add to the specified slot.
      Throws:
      IllegalArgumentException - if any of the components is a Text component.
      NullPointerException - if the components array is null.
    • addToSlot

      public static void addToSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.dom.Element... elements)
      Adds elements to the specified slot in the parent component.
      Parameters:
      parent - the parent component to add the elements to, not null
      slot - the name of the slot inside the parent, not null
      elements - elements to add to the specified slot.
      Throws:
      NullPointerException - if the elements array is null.
    • setSlot

      public static void setSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.component.Component... components)
      Clears the specific slot in the parent component and adds components to it.
      Parameters:
      parent - the parent component to add the components to, not null
      slot - the name of the slot inside the parent, not null
      components - components to add to the specified slot.
      Throws:
      NullPointerException - if the components array is null.
    • setSlot

      public static void setSlot(com.vaadin.flow.component.HasElement parent, String slot, com.vaadin.flow.dom.Element... elements)
      Clears the specific slot in the parent component and adds elements to it.
      Parameters:
      parent - the parent component to add the elements to, not null
      slot - the name of the slot inside the parent, not null
      elements - elements to add to the specified slot.
      Throws:
      NullPointerException - if the elements array is null.