Class Details

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.details.Details
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasTheme, HasThemeVariant<DetailsVariant>, HasTooltip, Serializable
Direct Known Subclasses:
AccordionPanel

@Tag("vaadin-details") @NpmPackage(value="@vaadin/details", version="25.1.0-alpha9") @JsModule("@vaadin/details/src/vaadin-details.js") public class Details extends Component implements HasComponents, HasSize, HasThemeVariant<DetailsVariant>, HasTooltip
Details is an expandable panel for showing and hiding content from the user to make the UI less crowded. Details consists of a summary and a content area.

The Summary is the part that is always visible, and typically describes the contents, for example, with a title. Clicking on the summary toggles the content area’s visibility. The summary supports rich content and can contain any component. This can be utilized for example to indicate the status of the corresponding content.

The content area is the collapsible part of Details. It can contain any component. When the content area is collapsed, the content is invisible and inaccessible by keyboard or screen reader.

Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • Details

      public Details()
      Initializes a new Details component.
    • Details

      public Details(String summary)
      Initializes a new Details using the provided summary.
      Parameters:
      summary - the summary component to set.
      See Also:
    • Details

      public Details(Component summary)
      Initializes a new Details using the provided summary.
      Parameters:
      summary - the summary component to set.
      See Also:
    • Details

      public Details(Signal<String> summaryTextSignal)
      Initializes a new Details component with a summary text provided by a signal.
      Parameters:
      summaryTextSignal - the signal that provides the summary text
    • Details

      public Details(String summary, Component content)
      Initializes a new Details using the provided summary and content.
      Parameters:
      summary - the summary text to set.
      content - the content component to add.
      See Also:
    • Details

      public Details(Component summary, Component content)
      Initializes a new Details using the provided summary and content.
      Parameters:
      summary - the summary component to set.
      content - the content component to add.
      See Also:
    • Details

      public Details(Signal<String> summaryTextSignal, Component content)
      Initializes a new Details component with a summary text provided by a signal and content.
      Parameters:
      summaryTextSignal - the signal that provides the summary text.
      content - the content component to add.
    • Details

      public Details(String summary, Component... components)
      Initializes a new Details using the provided summary and content components.
      Parameters:
      summary - the summary text to set.
      components - the content components to add.
      See Also:
    • Details

      public Details(Component summary, Component... components)
      Initializes a new Details using the provided summary and content components.
      Parameters:
      summary - the summary component to set.
      components - the content components to add.
      See Also:
    • Details

      public Details(Signal<String> summaryTextSignal, Component... components)
      Initializes a new Details component with a summary text provided by a signal and optional content components.
      Parameters:
      summaryTextSignal - the signal that provides the summary text.
      components - the content components to add.
  • Method Details

    • createSummaryContainer

      protected Component createSummaryContainer()
      Creates the summary container component.
      Returns:
      the summary container
    • setSummary

      public void setSummary(Component summary)
      Sets the component summary
      Parameters:
      summary - the summary component to set, or null to remove any previously set summary
      See Also:
    • getSummary

      public Component getSummary()
      Returns summary component which was set via setSummary(Component) or setSummaryText(String)
      Returns:
      the summary component, null if nothing was set
    • setSummaryText

      public void setSummaryText(String summary)
      Sets the summary text of the details component.
      Parameters:
      summary - the summary text to set, or null for empty text
      See Also:
    • getSummaryText

      public String getSummaryText()
      Returns:
      summary section content as string (empty string if nothing was set)
    • bindSummaryText

      public void bindSummaryText(Signal<String> signal)
      Binds a Signal's value to the summary text content of this component and keeps the summary text synchronized with the signal value while the element is in attached state. When the element is in detached state, signal value changes have no effect. null signal unbinds the existing binding.

      While a Signal is bound, any attempt to set the summary text manually throws

      invalid reference
      BindingActiveException
      . Same happens when trying to bind a new Signal while one is already bound.
      Parameters:
      signal - the signal to bind or null to unbind any existing binding
      See Also:
    • add

      public void add(Collection<Component> components)
      Adds components to the content section
      Specified by:
      add in interface HasComponents
      Parameters:
      components - the components to add
      See Also:
    • add

      public void add(String text)
      Adds the given text to the content section
      Specified by:
      add in interface HasComponents
      Parameters:
      text - the text to add, not null
      See Also:
    • remove

      public void remove(Collection<Component> components)
      Removes specified components from the content section
      Specified by:
      remove in interface HasComponents
      Parameters:
      components - the components to remove
    • removeAll

      public void removeAll()
      Removes all components from the content section
      Specified by:
      removeAll in interface HasComponents
    • addComponentAtIndex

      public void addComponentAtIndex(int index, Component component)
      Adds the given component to the content section at the specific index.

      In case the specified component has already been added to another parent, it will be removed from there and added to the content section of this one.

      Specified by:
      addComponentAtIndex in interface HasComponents
      Parameters:
      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count
      component - the component to add, value should not be null
    • bindChildren

      public <T, S extends Signal<T>> void bindChildren(Signal<List<S>> list, SerializableFunction<S,Component> childFactory)
      Description copied from interface: HasComponents
      Binds a list Signal to this component using a child component factory. Each item Signal in the list corresponds to a child component within this component.

      This component is automatically updated to reflect the structure of the list. Changes to the list, such as additions, removals, or reordering, will update this component's children accordingly.

      This component must not contain any children that are not part of the list. If this component has existing children when this method is called, or if it contains unrelated children after the list changes, an IllegalStateException will be thrown.

      New child components are created using the provided childFactory function. This function takes a Signal from the list and returns a corresponding Component. It shouldn't return null. The Signal can be further bound to the returned component as needed. Note that childFactory is run inside a Effect, and therefore Signal.get() calls makes effect re-run automatically on signal value change.

      Example of usage:

       SharedListSignal<String> taskList = new SharedListSignal<>(String.class);
      
       UnorderedList component = new UnorderedList();
      
       component.bindChildren(taskList, ListItem::new);
       

      Note: The default implementation adds children directly to the component’s element using the Element API and does not invoke HasComponents.add(Component...). Components that override add or manage children indirectly must override this method to provide a suitable implementation or explicitly disable it.

      Specified by:
      bindChildren in interface HasComponents
      Type Parameters:
      T - the value type of the Signals in the list
      S - the type of the Signals in the list
      Parameters:
      list - list signal to bind to the parent, must not be null
      childFactory - factory to create new component, must not be null
    • getContent

      public Stream<Component> getContent()
      Returns the content components which were added via HasComponents.add(Component...)
      Returns:
      the child components of the content section
    • isOpened

      @Synchronize(property="opened", value="opened-changed") public boolean isOpened()
      Returns:
      whether details are expanded or collapsed
    • setOpened

      public void setOpened(boolean opened)

      True if the details are opened and the content is displayed

      Parameters:
      opened - the boolean value to set
    • addOpenedChangeListener

      public Registration addOpenedChangeListener(ComponentEventListener<Details.OpenedChangeEvent> listener)
      Adds a listener to get notified when the opened state of the component changes.
      Parameters:
      listener - the listener
      Returns:
      a Registration for removing the event listener