com.vaadin.flow.component.popover.
Class Popover
All Implemented Interfaces:
AttachNotifier
, DetachNotifier
, HasAriaLabel
, HasComponents
, HasElement
, HasEnabled
, HasStyle
, HasTheme
, HasThemeVariant<PopoverVariant>
, Serializable
Popover is a component for creating overlays that are positioned next to specified component (target).
Author:
Vaadin Ltd.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
opened-changed
event is sent when the overlay opened state changes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Collection<Component> components) Adds the given components into this popover.
void
addComponentAtIndex
(int index, Component component) Adds the given component into this popover at the given index.
Add a listener for event fired by the
opened-changed
events.void
close()
Closes the popover.
Gets the aria-label of the component.
Gets the aria-labelledby of the component
Gets the set of CSS class names used for this element.
int
The delay in milliseconds before the popover is opened on target focus.
getFor()
Gets the
id
of target component of the popover, ornull
if theid
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.
Gets the ARIA role for the overlay element, used by screen readers.
Gets position of the popover with respect to its
target
.getStyle()
Gets the style instance for managing inline styles for the element of this 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
isModal()
Gets whether component is set as modal or modeless popover.
boolean
isOpened()
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.
protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.
void
open()
Opens the popover.
void
setAriaLabel
(String ariaLabel) Set the aria-label of the component to the given text.
void
setAriaLabelledBy
(String labelledBy) Set the aria-labelledby of the component.
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
setClassName
(String className) Sets the CSS class names of the popover overlay element.
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 popovertarget
value.void
Sets the height of the popover overlay 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
setOverlayRole
(String role) Sets the ARIA role for the overlay element, used by screen readers.
void
setPosition
(PopoverPosition position) Sets position of the popover with respect to its
target
.void
Sets the target component for this popover.
void
Sets 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, 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.HasComponents
add, add, addComponentAsFirst, 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, hasClassName, removeClassName, removeClassNames, 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
Creates a popover with given components inside.
Parameters:
components
- the components inside the popoverSee 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
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 addReturns:
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 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
-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
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 interfaceHasAriaLabel
Parameters:
ariaLabel
- the aria-label text to set ornull
to clear -
getAriaLabel
Description copied from interface:
HasAriaLabel
Gets the aria-label of the component.
Specified by:
getAriaLabel
in interfaceHasAriaLabel
Returns:
an optional aria-label of the component if no aria-label has been set
-
setAriaLabelledBy
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 interfaceHasAriaLabel
Parameters:
labelledBy
- the string with the id of the element that will be used as label ornull
to clear -
getAriaLabelledBy
Description copied from interface:
HasAriaLabel
Gets the aria-labelledby of the component
Specified by:
getAriaLabelledBy
in interfaceHasAriaLabel
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
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 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)
andsetOpenOnFocus(boolean)
tofalse
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)
andsetOpenOnFocus(boolean)
tofalse
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
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 setSee Also:
-
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
The
id
of the element to be used as the popovertarget
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 benull
to remove the target -
getFor
Gets the
id
of target component of the popover, ornull
if theid
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
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 benull
to remove the targetThrows:
IllegalArgumentException
- if the target is aText
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
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 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
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 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:
add
in 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:
addComponentAtIndex
in interfaceHasComponents
Parameters:
index
- the index, where the component will be added.component
- the component to add -
onAttach
Description copied from class:
Component
Called when the component is attached to a UI.
This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method. -
setClassName
Sets the CSS class names of the popover overlay element. This method overwrites any previous set class names.
Specified by:
setClassName
in interfaceHasStyle
Parameters:
className
- a space-separated string of class names to set, ornull
to remove all class names -
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 aSet
in Java.Specified by:
getClassNames
in interfaceHasStyle
Returns:
a list of class names, never
null
See Also:
-
getStyle
Description copied from interface:
HasStyle
Gets the style instance for managing inline styles for the element of this component.
Specified by:
getStyle
in interfaceHasStyle
Returns:
the style object for the element, not
null
Throws:
UnsupportedOperationException
- Popover does not support adding styles to overlay
-