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>.
Interactive Preview
Section titled “Interactive Preview”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> );}<script lang="ts"> import Popover from "@/components/ui/popover.svelte"; import PopoverTrigger from "@/components/ui/popover-trigger.svelte"; import PopoverPositioner from "@/components/ui/popover-positioner.svelte"; import PopoverContent from "@/components/ui/popover-content.svelte"; import PopoverTitle from "@/components/ui/popover-title.svelte"; import PopoverDescription from "@/components/ui/popover-description.svelte"; import PopoverCloseTrigger from "@/components/ui/popover-close-trigger.svelte";</script>
<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>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> );}Installation
Section titled “Installation”npx @glaceon/cli add popover --framework react # or svelte, solidData Attributes
Section titled “Data Attributes”| 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
hiddenattribute 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
hiddenclass.
API Reference (Props)
Section titled “API Reference (Props)”| 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().
Keyboard Interactions
Section titled “Keyboard Interactions”| 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 |
Accessibility
Section titled “Accessibility”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.