com.vaadin.flow.component.popover.

Class Popover

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.popover.Popover

All Implemented Interfaces:

AttachNotifier, DetachNotifier, HasAriaLabel, HasComponents, HasElement, HasEnabled, HasStyle, HasTheme, HasThemeVariant<PopoverVariant>, Serializable

@Tag("vaadin-popover") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.0-alpha7") @NpmPackage(value="@vaadin/popover",version="24.7.0-alpha7") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/popover/src/vaadin-popover.js") @JsModule("./vaadin-popover/popover.ts") public class Popover extends Component implements HasAriaLabel, HasComponents, HasThemeVariant<PopoverVariant>

Popover is a component for creating overlays that are positioned next to specified component (target).

Author:

Vaadin Ltd.

See Also:

  • Constructor Details

    • Popover

      public Popover()

      Constructs an empty popover.

    • Popover

      public Popover(Component... components)

      Creates a popover with given components inside.

      Parameters:

      components - the components inside the popover

      See Also:

  • Method Details

    • setDefaultFocusDelay

      public static void setDefaultFocusDelay(int defaultFocusDelay)

      Sets the default focus delay to be used by all popover instances (running in the same JVM), except for those that have focus delay configured using setFocusDelay(int).

      Parameters:

      defaultFocusDelay - the default focus delay

    • setDefaultHideDelay

      public static void setDefaultHideDelay(int defaultHideDelay)

      Sets the default hide delay to be used by all popover instances (running in the same JVM), except for those that have hide delay configured using setHideDelay(int).

      Parameters:

      defaultHideDelay - the default hide delay

    • setDefaultHoverDelay

      public static void setDefaultHoverDelay(int defaultHoverDelay)

      Sets the default hover delay to be used by all popover instances (running in the same JVM), except for those that have hover delay configured using setHoverDelay(int).

      Parameters:

      defaultHoverDelay - the default hover delay

    • setOpened

      public void setOpened(boolean opened)

      Opens or closes the popover.

      Parameters:

      opened - true to open the popover, false to close it

    • open

      public void open()

      Opens the popover.

    • close

      public void close()

      Closes the popover.

    • isOpened

      @Synchronize(property="opened", value="opened-changed") public boolean isOpened()

      Gets the open state from the popover.

      Returns:

      the opened property from the popover

    • addOpenedChangeListener

      public Registration addOpenedChangeListener(ComponentEventListener<Popover.OpenedChangeEvent> listener)

      Add a listener for event fired by the opened-changed events.

      Parameters:

      listener - the listener to add

      Returns:

      a Registration for removing the event listener

    • setModal

      public void setModal(boolean modal)

      Sets whether component should open modal or modeless popover. When the popover is modal, interacting with elements behind it will be prevented until the popover is closed.

      Setting the modal to true does not enable showing the backdrop (modality curtain) automatically. This should be done separately using setBackdropVisible(boolean) or optionally passed as a second parameter using setModal(boolean, boolean).

      NOTE: this setting does not involve server-side modality, as the modal popover is typically not used to prevent anything else from happening while it's open.

      By default, the popover is non-modal.

      Parameters:

      modal - true to enable popover to open as modal, false otherwise.

      See Also:

    • setModal

      public void setModal(boolean modal, boolean backdropVisible)

      Sets whether component should open modal or modeless popover and whether the component should show a backdrop (modality curtain) when opened.

      NOTE: this setting does not involve server-side modality, as the modal popover is typically not used to prevent anything else from happening while it's open.

      By default, the popover is non-modal and has no modality curtain.

      Parameters:

      modal - true to enable popover to open as modal, false otherwise.

      backdropVisible - true to show the backdrop, false otherwise.

      See Also:

    • isModal

      public boolean isModal()

      Gets whether component is set as modal or modeless popover. By default, the popover is non-modal.

      Returns:

      true if modal popover, false otherwise.

    • setBackdropVisible

      public void setBackdropVisible(boolean backdropVisible)

      Sets whether component should show a backdrop (modality curtain) when opened.

      By default, the backdrop is not shown.

      Parameters:

      backdropVisible - true to show the backdrop, false otherwise.

      See Also:

    • isBackdropVisible

      public boolean isBackdropVisible()

      Gets whether component shows a backdrop (modality curtain) when opened.

      Returns:

      true if backdrop is visible, false otherwise.

    • setAriaLabel

      public void setAriaLabel(String ariaLabel)

      Description copied from interface: HasAriaLabel

      Set the aria-label of the component to the given text.

      This method should not be used if HasAriaLabel.setAriaLabelledBy(String) is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.

      Specified by:

      setAriaLabel in interface HasAriaLabel

      Parameters:

      ariaLabel - the aria-label text to set or null to clear

    • getAriaLabel

      public Optional<String> getAriaLabel()

      Description copied from interface: HasAriaLabel

      Gets the aria-label of the component.

      Specified by:

      getAriaLabel in interface HasAriaLabel

      Returns:

      an optional aria-label of the component if no aria-label has been set

    • setAriaLabelledBy

      public void setAriaLabelledBy(String labelledBy)

      Description copied from interface: HasAriaLabel

      Set the aria-labelledby of the component. The value must be a valid id attribute of another element that labels the component. The label element must be in the same DOM scope of the component, otherwise screen readers may fail to announce the label content properly.

      This method should not be used if HasAriaLabel.setAriaLabel(String) is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.

      Specified by:

      setAriaLabelledBy in interface HasAriaLabel

      Parameters:

      labelledBy - the string with the id of the element that will be used as label or null to clear

    • getAriaLabelledBy

      public Optional<String> getAriaLabelledBy()

      Description copied from interface: HasAriaLabel

      Gets the aria-labelledby of the component

      Specified by:

      getAriaLabelledBy in interface HasAriaLabel

      Returns:

      an optional aria-labelledby of the component if no aria-labelledby has been set

    • setAutofocus

      public void setAutofocus(boolean autofocus)

      Set true to make the popover content automatically receive focus after it is opened. Modal popovers use this behavior by default.

      Parameters:

      autofocus - the boolean value to set

    • isAutofocus

      public boolean isAutofocus()

      Get if the popover content automatically receives focus after it is opened. Modal popovers use this behavior by default.

      Returns:

      true if the popover content receives focus when opened, false otherwise

    • setOverlayRole

      public void setOverlayRole(String role)

      Sets the ARIA role for the overlay element, used by screen readers.

      Parameters:

      role - the role to set

    • getOverlayRole

      public String getOverlayRole()

      Gets the ARIA role for the overlay element, used by screen readers. Defaults to dialog.

      Returns:

      the role

    • isCloseOnEsc

      public boolean isCloseOnEsc()

      Gets whether this popover can be closed by pressing the Esc key or not.

      By default, the popover is closable with Esc.

      Returns:

      true if this popover can be closed with the Esc key, false otherwise

    • setCloseOnEsc

      public void setCloseOnEsc(boolean closeOnEsc)

      Sets whether this popover can be closed by pressing the Esc key or not.

      By default, the popover is closable with Esc.

      NOTE: when none of the opening actions are specified by setting all of setOpenOnClick(boolean), setOpenOnHover(boolean) and setOpenOnFocus(boolean) to false this method does nothing as in this case the popover can be only closed programmatically.

      Parameters:

      closeOnEsc - true to enable closing this popover with the Esc key, false to disable it

    • isCloseOnOutsideClick

      public boolean isCloseOnOutsideClick()

      Gets whether this popover can be closed by clicking outside of it or not.

      By default, the popover is closable with an outside click.

      Returns:

      true if this popover can be closed by an outside click, false otherwise

    • setCloseOnOutsideClick

      public void setCloseOnOutsideClick(boolean closeOnOutsideClick)

      Sets whether this popover can be closed by clicking outside of it or not.

      By default, the popover is closable with an outside click.

      NOTE: when none of the opening actions are specified by setting all of setOpenOnClick(boolean), setOpenOnHover(boolean) and setOpenOnFocus(boolean) to false this method does nothing as in this case the popover can be only closed programmatically.

      Parameters:

      closeOnOutsideClick - true to enable closing this popover with an outside click, false to disable it

    • setPosition

      public void setPosition(PopoverPosition position)

      Sets position of the popover with respect to its target.

      NOTE: when the target component is not set, the position does not take any effect and the popover is rendered in the middle of the screen.

      Parameters:

      position - the position to set

      See Also:

    • getPosition

      public PopoverPosition getPosition()

      Gets position of the popover with respect to its target.

      NOTE: when the target component is not set, the position does not take any effect and the popover is rendered in the middle of the screen.

      Returns:

      the position

    • setFor

      public void setFor(String id)

      The id of the element to be used as the popover target value.

      The element should be in the DOM by the time when the attribute is set, otherwise a warning in the Javascript console is shown.

      Parameters:

      id - the id of target component for this popover, can be null to remove the target

    • getFor

      public String getFor()

      Gets the id of target component of the popover, or null if the id was not set.

      Returns:

      the id of target component for this popover

      See Also:

    • setFocusDelay

      public void setFocusDelay(int focusDelay)

      The delay in milliseconds before the popover is opened on target focus. When not specified, the default 500 milliseconds delay is used.

      Parameters:

      focusDelay - the delay in milliseconds

    • getFocusDelay

      public int getFocusDelay()

      The delay in milliseconds before the popover is opened on target focus. When not specified, the default 500 milliseconds delay is used.

      Returns:

      the delay in milliseconds

    • setHoverDelay

      public void setHoverDelay(int hoverDelay)

      The delay in milliseconds before the popover is opened on target hover. When not specified, the default 500 milliseconds delay is used.

      Parameters:

      hoverDelay - the delay in milliseconds

    • getHoverDelay

      public int getHoverDelay()

      The delay in milliseconds before the popover is opened on target hover. When not specified, the default 500 milliseconds delay is used.

      Returns:

      the delay in milliseconds

    • setHideDelay

      public void setHideDelay(int hideDelay)

      The delay in milliseconds before the popover is closed on losing hover. When not specified, the default 500 milliseconds delay is used.

      NOTE: on target blur, the popover is closed immediately.

      Parameters:

      hideDelay - the delay in milliseconds

    • getHideDelay

      public int getHideDelay()

      The delay in milliseconds before the popover is closed on losing hover. When not specified, the default 500 milliseconds delay is used.

      NOTE: on target blur, the popover is closed immediately.

      Returns:

      the delay in milliseconds

    • setOpenOnClick

      public void setOpenOnClick(boolean openOnClick)

      Sets whether the popover can be opened via target click. Defaults to true.

      Parameters:

      openOnClick - true to allow opening the popover via target click, false to disallow it.

    • isOpenOnClick

      public boolean isOpenOnClick()

      Gets whether the popover can be opened via target click. Defaults to true.

      Returns:

      true if the popover can be opened with target click, false otherwise.

    • setOpenOnFocus

      public void setOpenOnFocus(boolean openOnFocus)

      Sets whether the popover can be opened via target focus. Defaults to false.

      Parameters:

      openOnFocus - true to allow opening the popover via target focus, false to disallow it.

    • isOpenOnFocus

      public boolean isOpenOnFocus()

      Gets whether the popover can be opened via target focus. Defaults to false.

      Returns:

      true if the popover can be opened with target focus, false otherwise.

    • setOpenOnHover

      public void setOpenOnHover(boolean openOnHover)

      Sets whether the popover can be opened via target hover. Defaults to false.

      Parameters:

      openOnHover - true to allow opening the popover via target hover, false to disallow it.

    • isOpenOnHover

      public boolean isOpenOnHover()

      Gets whether the popover can be opened via target hover. Defaults to false.

      Returns:

      true if the popover can be opened with target hover, false otherwise.

    • setTarget

      public void setTarget(Component target)

      Sets the target component for this popover.

      By default, the popover can be opened with a click on the target component.

      Note: setting target will also add the popover to the <body> if it's not yet attached anywhere.

      Parameters:

      target - the target component for this popover, can be null to remove the target

      Throws:

      IllegalArgumentException - if the target is a Text component.

    • getTarget

      public Component getTarget()

      Gets the target component of this popover, or null if it doesn't have a target.

      Returns:

      the target component of this popover

      See Also:

    • setWidth

      public void setWidth(String width)

      Sets the width of the popover overlay content area.

      The width should be in a format understood by the browser, e.g. "100px" or "2.5em" (Using relative unit, such as percentage, will lead to unexpected results).

      If the provided width value is null then width is removed, and the popover overlay is auto-sized based on the content.

      Parameters:

      width - the width to set, may be null

    • setHeight

      public void setHeight(String height)

      Sets the height of the popover overlay content area.

      The height should be in a format understood by the browser, e.g. "100px" or "2.5em" (Using relative unit, such as percentage, will lead to unexpected results).

      If the provided height value is null then height is removed, and the popover overlay is auto-sized based on the content.

      Parameters:

      height - the height to set, may be null

    • add

      public void add(Collection<Component> components)

      Adds the given components into this popover.

      The elements in the DOM will not be children of the <vaadin-popover> element, but will be inserted into an overlay that is attached into the <body>.

      Specified by:

      add in interface HasComponents

      Parameters:

      components - the components to add

    • addComponentAtIndex

      public void addComponentAtIndex(int index, Component component)

      Adds the given component into this popover at the given index.

      The element in the DOM will not be child of the <vaadin-popover> element, but will be inserted into an overlay that is attached into the <body>.

      Specified by:

      addComponentAtIndex in interface HasComponents

      Parameters:

      index - the index, where the component will be added.

      component - the component to add

    • onAttach

      protected void onAttach(AttachEvent attachEvent)

      Description copied from class: Component

      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component.

      Make sure to call super.onAttach when overriding this method.

      Overrides:

      onAttach in class Component

      Parameters:

      attachEvent - the attach event

    • setClassName

      public void setClassName(String className)

      Sets the CSS class names of the popover overlay element. This method overwrites any previous set class names.

      Specified by:

      setClassName in interface HasStyle

      Parameters:

      className - a space-separated string of class names to set, or null to remove all class names

    • getClassNames

      public ClassList getClassNames()

      Description copied from interface: HasStyle

      Gets the set of CSS class names used for this element. The returned set can be modified to add or remove class names. The contents of the set is also reflected in the value of the class attribute.

      Despite the name implying a list being returned, the return type is actually a Set since the in-browser return value behaves like a Set in Java.

      Specified by:

      getClassNames in interface HasStyle

      Returns:

      a list of class names, never null

      See Also:

    • getStyle

      public Style getStyle()

      Description copied from interface: HasStyle

      Gets the style instance for managing inline styles for the element of this component.

      Specified by:

      getStyle in interface HasStyle

      Returns:

      the style object for the element, not null

      Throws:

      UnsupportedOperationException - Popover does not support adding styles to overlay