Class 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,com.vaadin.flow.component.shared.HasThemeVariant<PopoverVariant>,Serializable
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classopened-changedevent is sent when the popover opened state changes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Popover.OpenedChangeEvent> listener) Add a listener for event fired by theopened-changedevents.voidclose()Closes the popover.intThe delay in milliseconds before the popover is opened on target focus.getFor()Gets theidof target component of the popover, ornullif theidwas not set.intThe delay in milliseconds before the popover is closed on losing hover.intThe 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.Gets position of the popover with respect to itstarget.getRole()Gets the ARIA role for the popover element, used by screen readers.com.vaadin.flow.dom.StylegetStyle()com.vaadin.flow.component.ComponentGets the target component of this popover, ornullif it doesn't have a target.booleanGet if the popover content automatically receives focus after it is opened.booleanGets whether component shows a backdrop (modality curtain) when opened.booleanGets whether this popover can be closed by pressing the Esc key or not.booleanGets whether this popover can be closed by clicking outside of it or not.booleanisModal()Gets whether component is set as modal or modeless popover.booleanisOpened()Gets the open state from the popover.booleanGets whether the popover can be opened via target click.booleanGets whether the popover can be opened via target focus.booleanGets whether the popover can be opened via target hover.voidopen()Opens the popover.voidsetAutofocus(boolean autofocus) Settrueto make the popover content automatically receive focus after it is opened.voidsetBackdropVisible(boolean backdropVisible) Sets whether component should show a backdrop (modality curtain) when opened.voidsetCloseOnEsc(boolean closeOnEsc) Sets whether this popover can be closed by pressing the Esc key or not.voidsetCloseOnOutsideClick(boolean closeOnOutsideClick) Sets whether this popover can be closed by clicking outside of it or not.static voidsetDefaultFocusDelay(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 usingsetFocusDelay(int).static voidsetDefaultHideDelay(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 usingsetHideDelay(int).static voidsetDefaultHoverDelay(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 usingsetHoverDelay(int).voidsetFocusDelay(int focusDelay) The delay in milliseconds before the popover is opened on target focus.voidTheidof the element to be used as the popovertargetvalue.voidSets the height of the popover content area.voidsetHideDelay(int hideDelay) The delay in milliseconds before the popover is closed on losing hover.voidsetHoverDelay(int hoverDelay) The delay in milliseconds before the popover is opened on target hover.voidsetModal(boolean modal) Sets whether component should open modal or modeless popover.voidsetModal(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.voidsetOpened(boolean opened) Opens or closes the popover.voidsetOpenOnClick(boolean openOnClick) Sets whether the popover can be opened via target click.voidsetOpenOnFocus(boolean openOnFocus) Sets whether the popover can be opened via target focus.voidsetOpenOnHover(boolean openOnHover) Sets whether the popover can be opened via target hover.voidsetOverlayRole(String role) Deprecated, for removal: This API element is subject to removal in a future version.UsesetRole(String)insteadvoidsetPosition(PopoverPosition position) Sets position of the popover with respect to itstarget.voidSets the ARIA role for the popover element, used by screen readers.voidsetTarget(com.vaadin.flow.component.Component target) Sets the target component for this popover.voidSets 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
-
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:
-
-
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 usingsetFocusDelay(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 usingsetHideDelay(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 usingsetHoverDelay(int).- Parameters:
defaultHoverDelay- the default hover delay
-
setOpened
public void setOpened(boolean opened) Opens or closes the popover.- Parameters:
opened-trueto open the popover,falseto 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
openedproperty 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 theopened-changedevents.- 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
truedoes not enable showing the backdrop (modality curtain) automatically. This should be done separately usingsetBackdropVisible(boolean)or optionally passed as a second parameter usingsetModal(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-trueto enable popover to open as modal,falseotherwise.- 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-trueto enable popover to open as modal,falseotherwise.backdropVisible-trueto show the backdrop,falseotherwise.- See Also:
-
isModal
public boolean isModal()Gets whether component is set as modal or modeless popover. By default, the popover is non-modal.- Returns:
trueif modal popover,falseotherwise.
-
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-trueto show the backdrop,falseotherwise.- See Also:
-
isBackdropVisible
public boolean isBackdropVisible()Gets whether component shows a backdrop (modality curtain) when opened.- Returns:
trueif backdrop is visible,falseotherwise.
-
setAutofocus
public void setAutofocus(boolean autofocus) Settrueto 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:
trueif the popover content receives focus when opened,falseotherwise
-
setRole
Sets the ARIA role for the popover element, used by screen readers.- Parameters:
role- the role to set
-
setOverlayRole
Deprecated, for removal: This API element is subject to removal in a future version.UsesetRole(String)insteadSets the ARIA role for the popover, used by screen readers.- Parameters:
role- the role to set
-
getRole
Gets the ARIA role for the popover element, used by screen readers. Defaults todialog.- Returns:
- the role
-
getOverlayRole
Deprecated, for removal: This API element is subject to removal in a future version.UsegetRole()insteadGets the ARIA role for the popover, used by screen readers. Defaults todialog.- 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:
trueif this popover can be closed with the Esc key,falseotherwise
-
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)andsetOpenOnFocus(boolean)tofalsethis method does nothing as in this case the popover can be only closed programmatically.- Parameters:
closeOnEsc-trueto enable closing this popover with the Esc key,falseto 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:
trueif this popover can be closed by an outside click,falseotherwise
-
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)andsetOpenOnFocus(boolean)tofalsethis method does nothing as in this case the popover can be only closed programmatically.- Parameters:
closeOnOutsideClick-trueto enable closing this popover with an outside click,falseto disable it
-
setPosition
Sets position of the popover with respect to itstarget.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
Gets position of the popover with respect to itstarget.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
Theidof the element to be used as the popovertargetvalue.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 benullto remove the target
-
getFor
Gets theidof target component of the popover, ornullif theidwas 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 default500milliseconds 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 default500milliseconds 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 default500milliseconds 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 default500milliseconds 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 default500milliseconds 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 default500milliseconds 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 totrue.- Parameters:
openOnClick-trueto allow opening the popover via target click,falseto disallow it.
-
isOpenOnClick
public boolean isOpenOnClick()Gets whether the popover can be opened via target click. Defaults totrue.- Returns:
trueif the popover can be opened with target click,falseotherwise.
-
setOpenOnFocus
public void setOpenOnFocus(boolean openOnFocus) Sets whether the popover can be opened via target focus. Defaults tofalse.- Parameters:
openOnFocus-trueto allow opening the popover via target focus,falseto disallow it.
-
isOpenOnFocus
public boolean isOpenOnFocus()Gets whether the popover can be opened via target focus. Defaults tofalse.- Returns:
trueif the popover can be opened with target focus,falseotherwise.
-
setOpenOnHover
public void setOpenOnHover(boolean openOnHover) Sets whether the popover can be opened via target hover. Defaults tofalse.- Parameters:
openOnHover-trueto allow opening the popover via target hover,falseto disallow it.
-
isOpenOnHover
public boolean isOpenOnHover()Gets whether the popover can be opened via target hover. Defaults tofalse.- Returns:
trueif the popover can be opened with target hover,falseotherwise.
-
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 benullto remove the target- Throws:
IllegalArgumentException- if the target is aTextcomponent.
-
getTarget
public com.vaadin.flow.component.Component getTarget()Gets the target component of this popover, ornullif it doesn't have a target.- Returns:
- the target component of this popover
- See Also:
-
setWidth
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
widthvalue is null then width is removed, and the popover is auto-sized based on the content.- Parameters:
width- the width to set, may benull
-
setHeight
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
heightvalue is null then height is removed, and the popover is auto-sized based on the content.- Parameters:
height- the height to set, may benull
-
getStyle
public com.vaadin.flow.dom.Style getStyle()- Specified by:
getStylein interfacecom.vaadin.flow.component.HasStyle- Throws:
UnsupportedOperationException- Popover does not support adding styles
-
getRole()instead