Overview
A popover is a floating container that displays rich content anchored to a trigger element.Features
- Can be controlled or uncontrolled
- Customize side, alignment, offsets, collision handling
- Optionally render in a Portal
- Focus management and restoration
- Supports modal or non-modal mode
- Esc key closes the popover
- Clicking outside closes the popover
Installation
Anatomy
Import all parts and piece them together.API Reference
Root
Contains all the parts of a popover.The controlled open state of the popover. Must be used in conjunction with
onOpenChange.The open state of the popover when it is initially rendered. Use when you do not need to control its open state.
Event handler called when the open state of the popover changes.
The modality of the popover. When set to
true, interaction with outside elements will be disabled and only popover content will be visible to screen readers.Trigger
The button that toggles the popover.Change the default rendered element for the one passed as a child, merging their props and behavior.
Supports all standard HTML button attributes.
Anchor
An optional element to position the popover against. If not set, will position against the trigger.Change the default rendered element for the one passed as a child, merging their props and behavior.
Portal
When used, portals the content part into thebody.
Specify a container element to portal the content into.
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
Content
The component that pops out when the popover is open.Change the default rendered element for the one passed as a child, merging their props and behavior.
The preferred side of the trigger to render against when open.
The distance in pixels from the trigger.
The preferred alignment against the trigger. May change when collisions occur.
An offset in pixels from the “start” or “end” alignment options.
When
true, overrides the side and align preferences to prevent collisions with boundary edges.The element used as the collision boundary. By default this is the viewport.
The distance in pixels from the boundary edges where collision detection should occur.
The sticky behavior on the align axis.
partial will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst always will keep the content in the boundary regardless.Whether to hide the content when the trigger becomes fully occluded.
Event handler called when focus moves into the component after opening. It can be prevented by calling
event.preventDefault.Event handler called when focus moves to the trigger after closing. It can be prevented by calling
event.preventDefault.Event handler called when the escape key is down. It can be prevented by calling
event.preventDefault.Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling
event.preventDefault.Event handler called when an interaction happens outside the bounds of the component. It can be prevented by calling
event.preventDefault.Close
The button that closes the popover.Change the default rendered element for the one passed as a child, merging their props and behavior.
Arrow
An optional arrow element to render alongside the popover.Change the default rendered element for the one passed as a child, merging their props and behavior.
The width of the arrow in pixels.
The height of the arrow in pixels.
Example
Accessibility
Closes when the user presses the Esc key or interacts outside of the popover.Keyboard Interactions
Space- Opens/closes the popoverEnter- Opens/closes the popoverTab- Moves focus to the next focusable elementShift + Tab- Moves focus to the previous focusable elementEsc- Closes the popover and moves focus to trigger