Popover
When to use
- The content must be positioned relative to a button or a separate anchor.
- You need a portal, closing on Escape and correct positioning near the screen edge.
- The content is arbitrary markup for which there is no ready
SelectorMenu.
When not to use
- For a semantic list of actions, use
Menu. - Use
Tooltipfor text on hover/focus,HoverCardfor a preview with markup on hover over a link or a name, andDialogfor a blocking dialog. - Do not use it for content that must always be present in the page's DOM as part of the layout.
Minimal example
<Popover>
<PopoverTrigger asChild>
<Button>Filters</Button>
</PopoverTrigger>
<PopoverContent>
<FilterForm />
</PopoverContent>
</Popover>Public API
Popover is the Radix Root and accepts its controlled and uncontrolled props.
PopoverTrigger, PopoverAnchor and PopoverClose are the matching Radix
primitives; the trigger usually gets asChild to keep the Button semantics.
Always render the content through PopoverContent, not the bare Radix Content:
PopoverContent creates a portal, has align="start" and sideOffset={4} by default, and
accepts the rest of the Radix props (side, align, onOpenAutoFocus, etc.).
Accessibility and keyboard
Focus behavior, Escape and positioning are delegated to Radix. The content sits in
a portal on a layer above modal dialogs, so do not add local z-index patches
without a reason. The trigger must be an accessible interactive element; do
not turn an arbitrary div into a trigger without a role, focus and a name.
Good examples
- A filter button + a form in
PopoverContent. - A separate
PopoverAnchorwhen the panel is anchored to something other than the trigger. side="bottom" align="end"for a panel at the right edge of the button.
Anti-patterns
<PopoverContent>without aPopover/trigger as a permanent layer.- Duplicating
Portalor wrapping aPopoverinModalOverlay. - A list of commands with implicit navigation instead of
Menu.
Related sources and Storybook
src/components/overlays/Popover.tsxsrc/components/overlays/Popover.stories.tsx
TypeScript types
PopoverContentProps
Prop
Type
Plus DOM attributes, such as onChange, onClick, className — 279 in total; the table does not repeat them.