Popover
A popup anchored to a trigger element built on Base UI
Installation
bunx @prototyperco/cli add popoverpnpm dlx shadcn@latest add https://prototyper-ui.com/r/popover.jsonnpx shadcn@latest add https://prototyper-ui.com/r/popover.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/popover.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/popover.jsonThis will add the following files to your project:
components/ui/popover.tsx
Usage
import {
Popover,
PopoverTrigger,
PopoverContent,
} from "@/components/ui/popover";
<Popover>
<PopoverTrigger>Open</PopoverTrigger>
<PopoverContent>
<p>Popover content here.</p>
</PopoverContent>
</Popover>;Anatomy
<Popover>
<PopoverTrigger />
<PopoverContent>
<PopoverHeader>
<PopoverTitle />
<PopoverDescription />
</PopoverHeader>
{/* your content */}
</PopoverContent>
</Popover>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Popover | popover | Root provider, manages open/close state | Yes |
PopoverTrigger | popover-trigger | Element that toggles the popover | Yes |
PopoverContent | popover-content | The popup panel anchored to the trigger | Yes |
PopoverHeader | popover-header | Flex container for title and description | No |
PopoverTitle | popover-title | Accessible title for the popover | No |
PopoverDescription | popover-description | Accessible description for the popover | No |
Examples
Container Padding
Cross Offset
Flipping
Offset
Position
Styling
Data Slots
Use data-slot attributes to target specific parts of the popover:
| Slot name | Element |
|---|---|
popover | Root provider (no DOM rendered) |
popover-trigger | The trigger element |
popover-content | The popup panel |
popover-header | Header container |
popover-title | Title heading |
popover-description | Description text |
Customization Examples
/* Make popover wider */
[data-slot="popover-content"] {
@apply min-w-[16rem];
}
/* Style the popover title */
[data-slot="popover-title"] {
@apply text-base font-bold;
}{
/* Override styles via className */
}
<PopoverContent className="w-80 p-4">
<PopoverHeader className="mb-4">
<PopoverTitle>Settings</PopoverTitle>
</PopoverHeader>
{/* ... */}
</PopoverContent>;API Reference
Popover
Root component that manages open/close state.
Prop
Type
All Base UI Popover.Root props are forwarded via ...props.
PopoverTrigger
Element that toggles the popover when clicked.
Prop
Type
All Base UI Popover.Trigger props are forwarded via ...props.
PopoverContent
The popup panel rendered inside a portal with a positioner.
Prop
Type
All Base UI Popover.Popup props are forwarded via ...props.
PopoverHeader
Flex column container for title and description.
Prop
Type
Standard div props are forwarded via ...props.
PopoverTitle
Accessible title for the popover.
Prop
Type
All Base UI Popover.Title props are forwarded via ...props.
PopoverDescription
Accessible description for the popover.
Prop
Type
All Base UI Popover.Description props are forwarded via ...props.
Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Escape | Closes the popover |
Tab | Moves focus to the next focusable element within the popover |
Shift+Tab | Moves focus to the previous focusable element within the popover |
ARIA Attributes
PopoverContentreceivesrole="dialog"by default via Base UI.aria-labelledbyis automatically linked toPopoverTitlewhen present.aria-describedbyis automatically linked toPopoverDescriptionwhen present.- Focus moves into the popover when it opens.
- Focus returns to the trigger element when the popover closes.