Class Popover

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.popover.Popover
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, HasThemeVariant<PopoverVariant>, Serializable

@Tag("vaadin-popover") @NpmPackage(value="@vaadin/popover", version="25.0.0-alpha17") @JsModule("@vaadin/popover/src/vaadin-popover.js") @JsModule("./vaadin-popover/popover.ts") public class Popover extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, HasThemeVariant<PopoverVariant>
Popover is a component for creating overlays that are positioned next to specified component (target).
Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    opened-changed event is sent when the popover opened state changes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty popover.
    Popover(com.vaadin.flow.component.Component... components)
    Creates a popover with given components inside.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.shared.Registration
    addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Popover.OpenedChangeEvent> listener)
    Add a listener for event fired by the opened-changed events.
    void
    Closes the popover.
    int
    The delay in milliseconds before the popover is opened on target focus.
    Gets the id of target component of the popover, or null if the id was not set.
    int
    The delay in milliseconds before the popover is closed on losing hover.
    int
    The delay in milliseconds before the popover is opened on target hover.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use getRole() instead
    Gets position of the popover with respect to its target.
    Gets the ARIA role for the popover element, used by screen readers.
    com.vaadin.flow.dom.Style
     
    com.vaadin.flow.component.Component
    Gets the target component of this popover, or null if it doesn't have a target.
    boolean
    Get if the popover content automatically receives focus after it is opened.
    boolean
    Gets whether component shows a backdrop (modality curtain) when opened.
    boolean
    Gets whether this popover can be closed by pressing the Esc key or not.
    boolean
    Gets whether this popover can be closed by clicking outside of it or not.
    boolean
    Gets whether component is set as modal or modeless popover.
    boolean
    Gets the open state from the popover.
    boolean
    Gets whether the popover can be opened via target click.
    boolean
    Gets whether the popover can be opened via target focus.
    boolean
    Gets whether the popover can be opened via target hover.
    void
    Opens the popover.
    void
    setAutofocus(boolean autofocus)
    Set true to make the popover content automatically receive focus after it is opened.
    void
    setBackdropVisible(boolean backdropVisible)
    Sets whether component should show a backdrop (modality curtain) when opened.
    void
    setCloseOnEsc(boolean closeOnEsc)
    Sets whether this popover can be closed by pressing the Esc key or not.
    void
    setCloseOnOutsideClick(boolean closeOnOutsideClick)
    Sets whether this popover can be closed by clicking outside of it or not.
    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).
    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).
    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).
    void
    setFocusDelay(int focusDelay)
    The delay in milliseconds before the popover is opened on target focus.
    void
    The id of the element to be used as the popover target value.
    void
    setHeight(String height)
    Sets the height of the popover content area.
    void
    setHideDelay(int hideDelay)
    The delay in milliseconds before the popover is closed on losing hover.
    void
    setHoverDelay(int hoverDelay)
    The delay in milliseconds before the popover is opened on target hover.
    void
    setModal(boolean modal)
    Sets whether component should open modal or modeless popover.
    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.
    void
    setOpened(boolean opened)
    Opens or closes the popover.
    void
    setOpenOnClick(boolean openOnClick)
    Sets whether the popover can be opened via target click.
    void
    setOpenOnFocus(boolean openOnFocus)
    Sets whether the popover can be opened via target focus.
    void
    setOpenOnHover(boolean openOnHover)
    Sets whether the popover can be opened via target hover.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use setRole(String) instead
    void
    Sets position of the popover with respect to its target.
    void
    Sets the ARIA role for the popover element, used by screen readers.
    void
    setTarget(com.vaadin.flow.component.Component target)
    Sets the target component for this popover.
    void
    Sets the width of the popover content area.

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasAriaLabel

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, removeThemeVariants
  • Constructor Details

    • Popover

      public Popover()
      Constructs an empty popover.
    • Popover

      public Popover(com.vaadin.flow.component.Component... components)
      Creates a popover with given components inside.
      Parameters:
      components - the components inside the popover
      See Also:
      • HasComponents.add(Component...)
  • 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 com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.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.
    • 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
    • setRole

      public void setRole(String role)
      Sets the ARIA role for the popover element, used by screen readers.
      Parameters:
      role - the role to set
    • setOverlayRole

      @Deprecated(since="25.0", forRemoval=true) public void setOverlayRole(String role)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use setRole(String) instead
      Sets the ARIA role for the popover, used by screen readers.
      Parameters:
      role - the role to set
    • getRole

      public String getRole()
      Gets the ARIA role for the popover element, used by screen readers. Defaults to dialog.
      Returns:
      the role
    • getOverlayRole

      @Deprecated(since="25.0", forRemoval=true) public String getOverlayRole()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getRole() instead
      Gets the ARIA role for the popover, 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(com.vaadin.flow.component.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 com.vaadin.flow.component.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 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 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 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 is auto-sized based on the content.

      Parameters:
      height - the height to set, may be null
    • getStyle

      public com.vaadin.flow.dom.Style getStyle()
      Specified by:
      getStyle in interface com.vaadin.flow.component.HasStyle
      Throws:
      UnsupportedOperationException - Popover does not support adding styles