com.vaadin.flow.component.shared.

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 Details

    • SlotUtils

      public SlotUtils()
  • Method Details

    • getElementsInSlot

      public static Stream<Element> getElementsInSlot(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(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 Component getChildInSlot(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(HasElement parent, String slot, 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(HasElement parent, String slot, 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(HasElement parent, String slot, 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(HasElement parent, String slot, 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.