Popover
Usage
Examples
Show on focus
This example uses onFocusCapture and onBlurCapture events on Popover component
to determine if any element inside has focus:
With form
By default, focus trap inside popover is active, you can place forms inside and focus will be kept inside popover:
Show on hover
To show popover on hover add onMouseEnter and onMouseLeave handlers to
element that should trigger popover. Note that in this case you have to disable
focus trap with trapFocus={false}:
Position and placement
Popover position relative to target element is defined by:
- position – popover side – top, bottom, right or left, defaults to top
- placement – popover placement relative to position – start, center or end, defaults to center
- gutter – space between popover and target element in px, defaults to 10px
All positions and placement:
Control behavior
By default, popover:
- has focus trap
- closes when escape key is pressed
- closes when outside click is registered
Usually it is a good idea to turn these settings off, if you show popover on focus or hover:
Close button and title
Popover includes optional close button and title:
- set
withCloseButtonprop to show close button, addcloseButtonLabelto set aria-label attribute on close button - set
titleprop to add title at the top of popover
Control appearance
To change popover appearance use:
radius– applies border-radius fromtheme.radiusspacing– adds padding to all sides of popover fromtheme.spacingshadow– add box-shadow fromtheme.shadows
Initial focus
Popover uses use-focus-trap to manage focus.
To specify initial focus element add data-autofocus attribute:
Usage with other overlays
Popover listens for outside clicks with use-click-outside hook. This means that it is not possible to use elements that render overlays within Portal inside Popover. To use components like Autocomplete, Menu, DatePicker portal feature should be disabled for these components: