Class NativeDetails

All Implemented Interfaces:
AttachNotifier, ClickNotifier<NativeDetails>, DetachNotifier, HasElement, HasSize, HasStyle, Serializable

@Tag("details") public class NativeDetails extends HtmlComponent implements ClickNotifier<NativeDetails>
Component representing a <details> element.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • NativeDetails

      public NativeDetails()
      Creates a new details with an empty summary.
    • NativeDetails

      public NativeDetails(String summary)
      Creates a new details with the given summary.
      Parameters:
      summary - the summary to set.
    • NativeDetails

      public NativeDetails(Signal<String> summarySignal)
      Binds a signal's value to the summary text so that the text is updated when the signal's value is updated.

      While a binding for the summary text is active, any attempt to set the text manually throws BindingActiveException. The same happens when trying to bind a new Signal while one is already bound.

      Bindings are lifecycle-aware and only active while this component is in the attached state; they are deactivated while the component is in the detached state.

      Parameters:
      summarySignal - the signal to bind, not null
      Since:
      25.1
      See Also:
    • NativeDetails

      public NativeDetails(Component summaryContent)
      Creates a new details with the given content of the summary.
      Parameters:
      summaryContent - the summary content to set.
    • NativeDetails

      public NativeDetails(String summary, Component content)
      Creates a new details using the provided summary and content.
      Parameters:
      summary - the summary text to set.
      content - the content component to set.
    • NativeDetails

      public NativeDetails(Signal<String> summarySignal, Component content)
      Creates a new details using the provided summary signal and content.
      Parameters:
      summarySignal - the signal to bind, not null
      content - the content component to set.
      Since:
      25.1
      See Also:
    • NativeDetails

      public NativeDetails(Component summaryContent, Component content)
      Creates a new details using the provided summary content and content.
      Parameters:
      summaryContent - the summary content to set.
      content - the content component to set.
  • Method Details

    • getSummary

      public NativeDetails.Summary getSummary()
      Returns NativeDetails.Summary component associated with this details.
      Returns:
      the summary component
    • getSummaryText

      public String getSummaryText()
      Returns the textual summary of this details.
      Returns:
      the text content of the summary, not null
      See Also:
    • setSummaryText

      public void setSummaryText(String summary)
      Sets the text of the summary. Removes previously set components of the summary.
      Parameters:
      summary - the summary text to set.
      See Also:
    • bindSummaryText

      public void bindSummaryText(Signal<String> summarySignal)
      Binds a signal's value to the summary text so that the text is updated when the signal's value is updated.

      While a binding for the summary text is active, any attempt to set the text manually throws BindingActiveException. The same happens when trying to bind a new Signal while one is already bound.

      Bindings are lifecycle-aware and only active while this component is in the attached state; they are deactivated while the component is in the detached state.

      Parameters:
      summarySignal - the signal to bind, not null
      Throws:
      BindingActiveException - thrown when there is already an existing binding
      Since:
      25.1
      See Also:
    • setSummary

      public void setSummary(Component... summaryContent)
      Sets the components of the summary. Removes previously set text or components of the summary.
      Parameters:
      summaryContent - the summary content to set.
      See Also:
    • getContent

      public Component getContent()
      Returns the details content which was set via setContent(Component).
      Returns:
      the content of the details, can be null.
    • setContent

      public void setContent(Component content)
      Sets the details content and removes the previously set content.
      Parameters:
      content - the content of the details to set
      See Also:
    • isOpen

      @Synchronize(property="open", value="toggle", allowInert=true) public boolean isOpen()
      Return whether or not the details is opened and the content is displayed.
      Returns:
      whether details are expanded or collapsed
    • setOpen

      public void setOpen(boolean open)
      Sets whether or not the details should be opened. true if the details should be opened and the content should be displayed, false to collapse it.
      Parameters:
      open - the boolean value to set
    • addToggleListener

      public Registration addToggleListener(ComponentEventListener<NativeDetails.ToggleEvent> listener)
      Adds a listener for toggle events fired by the details, which are dispatched to the details element whenever its state changes between open and closed.

      Note: This event is always triggered on client side. Resulting in isFromClient() to always return true.

      Parameters:
      listener - the listener
      Returns:
      a Registration for removing the event listener