Popover

A panel anchored to a trigger, opened by a person or an agent.

Source
$npx @dinachi/cli@latest add popover
side
align
sideOffset
PopoverClose

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

Settings with a close button and controls inside.
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>
  );
}

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

openboolean
Controlled open state.
defaultOpenboolean = false
Starting state when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs for people and agents. details.cancel() refuses the change.
onOpenChangeComplete(open) => void
Runs once the open or close animation ends.
modalboolean | "trap-focus" = false
Locks page scroll and outside clicks while open. "trap-focus" only traps focus.
handlePopoverHandle
Links triggers rendered elsewhere. Make one with createPopoverHandle().
childrenReactNode | ({ payload }) => ReactNode
A function receives the opening trigger's payload.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as popover.

Reads

label

The trigger's name while closed; while open, the PopoverTitle, falling back to the trigger's name.

open

Whether 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 PopoverTitle and described by PopoverDescription.
  • 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.