Class Popover
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasAriaLabel,HasComponents,HasElement,HasEnabled,HasStyle,HasTheme,HasThemeVariant<PopoverVariant>,Serializable
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classopened-changedevent is sent when the overlay opened state changes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Collection<Component> components) Adds the given components into this popover.voidaddComponentAtIndex(int index, Component component) Adds the given component into this popover at the given index.Add a listener for event fired by theopened-changedevents.voidclose()Closes the popover.Gets the aria-label of the component.Gets the aria-labelledby of the componentGets the set of CSS class names used for this element.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.Gets the ARIA role for the overlay element, used by screen readers.Gets position of the popover with respect to itstarget.getStyle()Gets the style instance for managing inline styles for the element of this component.Gets 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.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidopen()Opens the popover.voidsetAriaLabel(String ariaLabel) Set the aria-label of the component to the given text.voidsetAriaLabelledBy(String labelledBy) Set the aria-labelledby of the component.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.voidsetClassName(String className) Sets the CSS class names of the popover overlay element.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 overlay 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) Sets the ARIA role for the overlay element, used by screen readers.voidsetPosition(PopoverPosition position) Sets position of the popover with respect to itstarget.voidSets the target component for this popover.voidSets the width of the popover overlay 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, 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.HasComponents
add, add, addComponentAsFirst, 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, hasClassName, removeClassName, removeClassNames, 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
-
Constructor Details
-
Popover
public Popover()Constructs an empty popover. -
Popover
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
Gets the open state from the popover.- Returns:
- the
openedproperty from the popover
-
addOpenedChangeListener
public Registration addOpenedChangeListener(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.
-
setAriaLabel
Description copied from interface:HasAriaLabelSet 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:
setAriaLabelin interfaceHasAriaLabel- Parameters:
ariaLabel- the aria-label text to set ornullto clear
-
getAriaLabel
Description copied from interface:HasAriaLabelGets the aria-label of the component.- Specified by:
getAriaLabelin interfaceHasAriaLabel- Returns:
- an optional aria-label of the component if no aria-label has been set
-
setAriaLabelledBy
Description copied from interface:HasAriaLabelSet 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:
setAriaLabelledByin interfaceHasAriaLabel- Parameters:
labelledBy- the string with the id of the element that will be used as label ornullto clear
-
getAriaLabelledBy
Description copied from interface:HasAriaLabelGets the aria-labelledby of the component- Specified by:
getAriaLabelledByin interfaceHasAriaLabel- Returns:
- an optional aria-labelledby of the component if no aria-labelledby has been set
-
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
-
setOverlayRole
Sets the ARIA role for the overlay element, used by screen readers.- Parameters:
role- the role to set
-
getOverlayRole
Gets the ARIA role for the overlay element, 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
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
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 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
widthvalue is null then width is removed, and the popover overlay is auto-sized based on the content.- Parameters:
width- the width to set, may benull
-
setHeight
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
heightvalue is null then height is removed, and the popover overlay is auto-sized based on the content.- Parameters:
height- the height to set, may benull
-
add
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:
addin interfaceHasComponents- Parameters:
components- the components to add
-
addComponentAtIndex
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:
addComponentAtIndexin interfaceHasComponents- Parameters:
index- the index, where the component will be added.component- the component to add
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method. -
setClassName
Sets the CSS class names of the popover overlay element. This method overwrites any previous set class names.- Specified by:
setClassNamein interfaceHasStyle- Parameters:
className- a space-separated string of class names to set, ornullto remove all class names
-
getClassNames
Description copied from interface:HasStyleGets 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 theclassattribute.Despite the name implying a list being returned, the return type is actually a
Setsince the in-browser return value behaves like aSetin Java.- Specified by:
getClassNamesin interfaceHasStyle- Returns:
- a list of class names, never
null - See Also:
-
getStyle
Description copied from interface:HasStyleGets the style instance for managing inline styles for the element of this component.- Specified by:
getStylein interfaceHasStyle- Returns:
- the style object for the element, not
null - Throws:
UnsupportedOperationException- Popover does not support adding styles to overlay
-