sidealignsideOffsetPopoverCloseimport { Settings, X } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger } from "@/components/ui/popover"
export function SettingsPopover() {
return (
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>
<Settings className="mr-2 h-4 w-4" />
Settings
</PopoverTrigger>
<PopoverContent className="w-72">
<div className="mb-2 flex items-start justify-between">
<PopoverTitle>Settings</PopoverTitle>
<PopoverClose aria-label="Close" render={<button className="rounded-sm opacity-70 hover:opacity-100" />}>
<X className="h-4 w-4" />
</PopoverClose>
</div>
<PopoverDescription>Configure your application settings here.</PopoverDescription>
<div className="mt-4 space-y-2">
<label className="flex items-center justify-between text-sm">
Enable notifications
<input type="checkbox" className="rounded" />
</label>
<label className="flex items-center justify-between text-sm">
Auto-save
<input type="checkbox" className="rounded" defaultChecked />
</label>
</div>
</PopoverContent>
</Popover>
)
}Usage
import {
Popover,
PopoverContent,
PopoverDescription,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
import { Button } from "@/components/ui/button"
export function Filters() {
return (
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>Filters</PopoverTrigger>
<PopoverContent>
<PopoverTitle>Filters</PopoverTitle>
<PopoverDescription>Narrow the list by status and owner.</PopoverDescription>
</PopoverContent>
</Popover>
)
}Examples
import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverTitle,
PopoverDescription,
PopoverClose
} from '@/components/ui/popover';
import { Settings, X } from 'lucide-react';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>
<Settings className="mr-2 h-4 w-4" />
Settings
</PopoverTrigger>
<PopoverContent className="w-80">
<div className="flex items-start justify-between mb-2">
<PopoverTitle>Settings</PopoverTitle>
<PopoverClose render={<button className="rounded-sm opacity-70 hover:opacity-100" />}>
<X className="h-4 w-4" />
</PopoverClose>
</div>
<PopoverDescription>
Configure your application settings here.
</PopoverDescription>
<div className="mt-4 space-y-2">
<div className="flex items-center justify-between">
<label className="text-sm">Enable notifications</label>
<input type="checkbox" className="rounded" />
</div>
<div className="flex items-center justify-between">
<label className="text-sm">Auto-save</label>
<input type="checkbox" className="rounded" defaultChecked />
</div>
</div>
</PopoverContent>
</Popover>
);
}import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverArrow,
PopoverTitle,
PopoverDescription
} from '@/components/ui/popover';
import { Bell } from 'lucide-react';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<Popover>
<PopoverTrigger render={<Button variant="outline" size="icon" />}>
<Bell className="h-4 w-4" />
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverTitle>Notifications</PopoverTitle>
<PopoverDescription>
You are all caught up. Good job!
</PopoverDescription>
</PopoverContent>
</Popover>
);
}import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverArrow,
PopoverTitle,
PopoverDescription
} from '@/components/ui/popover';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<div className="flex gap-4 flex-wrap">
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>Top</PopoverTrigger>
<PopoverContent side="top">
<PopoverArrow />
<PopoverTitle>Top Position</PopoverTitle>
<PopoverDescription>Opens at the top.</PopoverDescription>
</PopoverContent>
</Popover>
<Popover>
<PopoverTrigger render={<Button variant="outline" />}>Bottom</PopoverTrigger>
<PopoverContent side="bottom">
<PopoverArrow />
<PopoverTitle>Bottom Position</PopoverTitle>
<PopoverDescription>Opens at the bottom.</PopoverDescription>
</PopoverContent>
</Popover>
</div>
);
}import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverArrow,
PopoverTitle,
PopoverDescription
} from '@/components/ui/popover';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<Popover>
<PopoverTrigger openOnHover delay={200} closeDelay={100} render={<Button variant="outline" />}>Hover me</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverTitle>Hover Popover</PopoverTitle>
<PopoverDescription>
Opens when you hover over the trigger.
</PopoverDescription>
</PopoverContent>
</Popover>
);
}import {
Popover,
PopoverTrigger,
PopoverPortal,
PopoverPositioner,
PopoverPopup,
PopoverArrow,
PopoverViewport,
PopoverTitle,
PopoverDescription,
createPopoverHandle,
} from '@/components/ui/popover';
import { Button } from '@/components/ui/button';
const tabs = [
{ id: 'profile', label: 'Profile', title: 'Your Profile', description: 'Manage your display name, avatar, and public bio.' },
{ id: 'account', label: 'Account', title: 'Account Settings', description: 'Update your email, password, and two-factor authentication.' },
{ id: 'billing', label: 'Billing', title: 'Billing & Plans', description: 'View invoices, update payment methods, and change your plan.' },
];
export function Example() {
const handle = createPopoverHandle();
return (
<div className="flex gap-2">
{tabs.map((tab) => (
<PopoverTrigger
key={tab.id}
handle={handle}
payload={tab}
openOnHover
delay={200}
closeDelay={150}
render={(props) => (
<Button variant="outline" size="sm" {...props}>{tab.label}</Button>
)}
/>
))}
<Popover handle={handle}>
{({ payload }) => {
const tab = payload as (typeof tabs)[number] | undefined;
return (
<PopoverPortal>
<PopoverPositioner sideOffset={8}>
<PopoverPopup>
<PopoverArrow />
<PopoverViewport>
{tab && (
<>
<PopoverTitle>{tab.title}</PopoverTitle>
<PopoverDescription>{tab.description}</PopoverDescription>
</>
)}
</PopoverViewport>
</PopoverPopup>
</PopoverPositioner>
</PopoverPortal>
);
}}
</Popover>
</div>
);
}Notes
Inside a Dialog or Drawer
PopoverContent portals into the body by default. Pass portal={false} inside a Dialog or Drawer to stay in their stacking and focus scope.
One popup, many triggers
Pass one createPopoverHandle() to the Popover and each PopoverTrigger, and give each trigger a payload. The children function receives it; PopoverViewport animates between contents. Agents see triggers outside the Popover as plain buttons.
API
details.cancel() refuses the change.createPopoverHandle().Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Agent
Inside an AgentProvider, it appears in agent.snapshot() as popover.
Reads
labelThe trigger's name while closed; while open, the PopoverTitle, falling back to the trigger's name.
openWhether the popup is showing.
Actions
open()Opens the popup. Only while closed.
close()Closes the popup. Only while open.
While open, the popover and its contents are listed before the page. An agent's change runs through onOpenChange; isAgentChange(details) is true for it, and details.cancel() refuses it. The agent is told the app refused.
await agent.act({
steps: [{ ref: "Settings", action: "open" }],
})Accessibility
- The popup is a dialog, named by
PopoverTitleand described byPopoverDescription. - The trigger reports whether the popup is open.
- Give an icon-only trigger an aria-label. The agent reads the same name.
- Focus moves into the popup on open and back to the trigger on close.