Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Popover

A popover anchored to a trigger, positioned automatically by Zag.js. Clicking outside or pressing Escape dismisses it, and the trigger carries the correct aria-expanded and aria-controls state throughout.

The panel renders into a portal on document.body, so it is never clipped by an ancestor’s overflow or trapped inside a stacking context.

The component is composed from parts. <Popover> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Popover>.

React Popoverlive
import {
Popover,
PopoverTrigger,
PopoverPositioner,
PopoverContent,
PopoverTitle,
PopoverDescription,
PopoverCloseTrigger,
} from "@/components/ui/popover";
export function Notifications() {
return (
<Popover>
<PopoverTrigger>Open notifications</PopoverTrigger>
<PopoverPositioner>
<PopoverContent>
<PopoverTitle>Notification settings</PopoverTitle>
<PopoverDescription>
Choose how you want to be told about changes to this workspace.
</PopoverDescription>
<PopoverCloseTrigger />
</PopoverContent>
</PopoverPositioner>
</Popover>
);
}
Terminal window
npx @glaceon/cli add popover --framework react # or svelte, solid
Attribute Values Applied to
data-scope popover every part
data-part trigger, positioner, content, title, description, close-trigger matching part
data-state open, closed trigger, content

Two behaviours are essential when styling this component:

  • The content receives the hidden attribute while closed. Do not add an unconditional Tailwind display utility to it: a utility and the [hidden] rule have equal specificity, and the utility wins, which leaves a closed panel visible.
  • The positioner is never hidden. Zag hides the content inside it, so the positioner must stay rendered and must not carry an unconditional hidden class.
Part Prop Type Description
Popover children ReactNode / Snippet / JSX.Element The trigger and panel
Popover defaultOpen boolean Open on first render
Popover onOpenChange (details: { open: boolean }) => void Called whenever the open state changes
PopoverTrigger children content Trigger label
PopoverPositioner children content Wraps the content; handles anchoring and the portal
PopoverContent children content The panel itself
PopoverTitle children content Panel title, wired to aria-labelledby
PopoverDescription children content Wired to aria-describedby
PopoverCloseTrigger className / class string Close button; carries aria-label="Close"

Every part also accepts className (React) or class (Svelte, Solid), merged over the base classes with cn().

Key Behaviour
Enter / Space Opens the popover when the trigger is focused
Tab Moves focus through the panel; focus returns to the trigger on close
Escape Closes the popover

Anchoring, click-outside dismissal, Escape handling, and the aria-expanded / aria-controls wiring on the trigger all come from the Zag.js machine. The trigger and the close button meet the 44px minimum target size (WCAG 2.2 SC 2.5.8), and both use the --action focus ring at 2px.