Popover is a non-modal dialog that floats around a trigger. It's used to display
contextual information to the user, and should be paired with a clickable
trigger element.
When using this component, ensure the children passed to PopoverTrigger is
focusable. Users can tab to it using their keyboard, and it can take a ref.
It's critical for accessiblity.
A11y: When Popover opens, focus is sent to PopoverContent. When it
closes, focus is returned to the trigger.
Confirmation!
Are you sure you want to have that milkshake?
<Popover>
<PopoverTrigger>
<Button>Trigger</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow/>
<PopoverCloseButton/>
<PopoverHeader>Confirmation!</PopoverHeader>
<PopoverBody>Are you sure you want to have that milkshake?</PopoverBody>
Chakra exports all the components you need to customize the look and feel of the
popover. You can change the background, arrow size, box shadow and so on.
Click
Customization
Tadaa!! The arrow color and background color is customized. Check the props for each component.
Since popover is powered by PopperJS, you can change the placement of the
popover by passing the placement prop. See the props for the
possible placement values.
Even though you specified the placement, Popover will try to reposition itself
in the event that available space at the specified placement isn't enough.
Popover placement
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore.
By default, the Popover component renders children of PopoverContent to the
DOM, meaning that invisible popover contents are still rendered but are hidden
by styles.
If you want to defer rendering of popover content until that Popover is
opened, you can use the isLazy prop. This is useful if your PopoverContent
needs to be extra performant, or make network calls on mount that should only
happen when the component is displayed.
When the popover is opened, focus is moved to the PopoverContent. If the
initialFocusRef is set, then focus moves to the element with that ref.
When the popover is closed, focus returns to the trigger. If you set
returnFocusOnClose to false, focus will not return.
If trigger is set to hover:
Focusing on or mousing over the trigger will open the popover
Blurring or mousing out of the trigger will close the popover. If you move
your mouse into the PopoverContent, it'll remain visible.
If trigger is set to click:
Clicking the trigger or using the Space or Enter when focus is on the
trigger will open the popover.
Clicking the trigger again will close the popover.
Hitting the Esc key while the popover is open and focus is within the
PopoverContent, will close the popover. If you set closeOnEsc to false,
it will not close.
Clicking outside or blurring out of the PopoverContent closes the popover.
If you set closeOnBlur to false, it will not close.
If the trigger is set to click, the PopoverContent element has role set to
dialog. If the trigger is set to hover, the PopoverContent has role
set to tooltip.
The PopoverContent has aria-labelledby set to the id of the
PopoverHeader.
The PopoverContent has aria-describedby set to the id of the
PopoverBody.
The PopoverContent has aria-hidden set to true or false depending on
the open/closed state of the popover.
The trigger has aria-haspopup set to true to denote that it triggers a
popover.
The trigger has aria-controls set to the id of the PopoverContent to
associate the popover and the trigger.
The trigger has aria-expanded set to true or false depending on the
open/closed state of the popover.
The gap (in pixels) to apply between the popover and the target. Used by popper.js
usePortal
boolean
false
If true the popover is displayed with a Portal. Rendering content inside a Portal allows the popover content to escape the physical bounds of its parent while still being positioned correctly relative to its target
onOpen
() => void
Callback fired when the popover opens
onClose
() => void
Callback fired when the popover closes
isLazy
boolean
If true, the popover content won't render until the popover is open.