Use the Popover component to display additional content or information in a small overlay that appears near the target element when triggered by a click. Popovers are useful for providing context-sensitive details without navigating away from the current page. They can be used for detailed information, tooltips with actions, interactive content, contextual help, or for notifications and alerts.
Preview
To initialize the popover, call the popover function with a trigger and popover property, where:
trigger: References the trigger element through a query selector.
trigger: References the Popover component through a query selector.
By default, the popover will appear under the trigger element with a 10pxmargin-top. To change the amount of margin, you can pass an offset property to the popover function:
0 offset
20px offset
Closing Functionality
Opened popovers can be closed by clicking again on the trigger element, clicking outside of the popover, or hitting Esc on the keyboard. This behavior can be configured using the closeOnBlur and closeOnEsc properties, and the closePopover function:
You can also destroy popovers if you want to disable them or remove the related event listeners when a component unmounts. To achieve this, assign the popover function call to a variable, and call the remove method on the variable. This will render the popover non-interactive.
Close the popover using the closePopover function.
Remove the popover instance using the remove method.
Optionally disable the trigger button to indicate that the popover has been removed.
Positions
The Popover component also supports the following 12 different positions:
To change the position of the popover, specify the position property:
Popover Events
When calling the popover function, you can also optionally pass an onOpen and onClose property to the configuration object to listen to open and close events:
Both methods has access to an object with the following properties:
trigger: The DOM node for the trigger element.
popover: The DOM node for the Popover component.
position: The popover position.
JavaScript API
Param
Default
Purpose
trigger
-
Pass a query selector for the trigger element.
popover
-
Pass a query selector for the popover that should be triggered.
offset
10
Sets the margin of the popover from the trigger element.
position
bottom
Sets the position of the popover relative to the trigger element.
closeOnBlur
true
Sets whether the popover should close when the user clicks outside of it.
closeOnEsc
true
Sets whether the popover should close when the user clicks the Esc key.
onOpen
-
Callback function executed after a popover is opened.
onClose
-
Callback function executed after a popover is closed.