Overlays
Popover
Free18.5 KB gzippedAccessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Enter, Space, Escape and 2 more · Full report
Import
import { Popover } from "@vjdesigns/vjdesigns-ui";
Importing only Popover adds about 18.5 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
A non-modal panel anchored to its trigger. It closes on Escape, an outside click, or when focus leaves it.
import { Popover } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<Popover>
<Popover.Trigger variant="outline" tone="neutral">
What's new?
</Popover.Trigger>
<Popover.Content showArrow showClose>
<Popover.Title>Version 1.1</Popover.Title>
<Popover.Description>Command palette, tree view and a new Timeline layout. See the changelog for details.</Popover.Description>
</Popover.Content>
</Popover>
);
}
With form
Popovers can hold interactive content, like a small form. placement picks the side.
import { Field, Flex, Input, Popover, Stack } from "@vjdesigns/vjdesigns-ui";
export function WithForm() {
return (
<Popover placement="bottom-start">
<Popover.Trigger>Rename</Popover.Trigger>
<Popover.Content size="sm">
<form onSubmit={(event) => event.preventDefault()}>
<Stack gap={3}>
<Popover.Title level={3}>Rename file</Popover.Title>
<Field label="File name">
<Input defaultValue="launch-plan.pdf" />
</Field>
<Flex gap={2} justify="end">
<Popover.Close variant="ghost" tone="neutral" size="sm">
Cancel
</Popover.Close>
<Popover.Close size="sm" type="submit">
Save
</Popover.Close>
</Flex>
</Stack>
</form>
</Popover.Content>
</Popover>
);
}
Custom trigger
Any element can be the trigger with asChild.
import { Button, Popover } from "@vjdesigns/vjdesigns-ui";
export function CustomTrigger() {
return (
<Popover placement="top">
<Popover.Trigger asChild>
<Button variant="link">Why do we ask?</Button>
</Popover.Trigger>
<Popover.Content size="sm" showArrow>
<Popover.Description>We use your birthday to verify your identity if you lose access to your account.</Popover.Description>
</Popover.Content>
</Popover>
);
}
Accessibility
Use modal for short tasks that must be finished or dismissed: it traps Tab inside the popover and sets aria-modal="true". Popover.Title gives it a heading, and the close button is named.
import {
Button,
Field,
Flex,
Input,
Popover,
Stack,
} from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Popover modal placement="bottom-start">
<Popover.Trigger variant="outline" tone="neutral">
Share
</Popover.Trigger>
<Popover.Content showClose>
<Stack gap={3}>
<Popover.Title>Share this file</Popover.Title>
<Field label="Email address">
<Input type="email" autoComplete="email" fullWidth />
</Field>
<Flex justify="end" gap={2}>
<Popover.Close variant="ghost" tone="neutral">
Cancel
</Popover.Close>
<Button>Send</Button>
</Flex>
</Stack>
</Popover.Content>
</Popover>
);
}
Translated
The close button's name comes from the locale (Japanese here), and the popover keeps the language of the area that opened it.
import { Popover, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ja from "@vjdesigns/vjdesigns-ui/locales/ja";
export function Translated() {
return (
<LocaleProvider locale="ja" messages={ja}>
<Popover>
<Popover.Trigger variant="outline" tone="neutral">
新機能
</Popover.Trigger>
<Popover.Content showArrow showClose>
<Popover.Title>バージョン 1.3</Popover.Title>
<Popover.Description>32 言語に対応した翻訳機能が追加されました。</Popover.Description>
</Popover.Content>
</Popover>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
Popover
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
openControlled open state. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state whenever it changes. | (open: boolean) => void | — |
placementPreferred side and alignment relative to the anchor. Flips when there isn't room. | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom" |
offsetGap between the anchor and the popover, in px. Defaults to 8, or 12 with | number | — |
modalModal mode: traps Tab inside the popover and sets | boolean | false |
closeOnOutsidePressClose when the user presses outside the popover, trigger, and anchor. | boolean | true |
closeOnEscapeClose when the user presses Escape. Nested popovers close innermost first. | boolean | true |
closeOnFocusOutClose when keyboard focus moves outside the popover (non-modal only). | boolean | true |
closeOnAnchorFocusClose when focus moves to the | boolean | false |
Popover.Trigger
| Prop | Type | Default |
|---|---|---|
childrenRequiredA single element (usually a | ReactNode | — |
asChildClone the single child instead of wrapping it in a | boolean | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the label. Hidden from assistive technology. | ReactNode | — |
fullWidthStretches the button to fill its container. Inherits from a surrounding | boolean | false |
Also accepts native <button> attributes, plus className, style and ref.
Popover.Anchor
| Prop | Type | Default |
|---|---|---|
childrenThe element to position against. A single element is used as-is; other content is wrapped in a | ReactNode | — |
asChildClone the single child instead of wrapping it. Defaults to | boolean | — |
Also accepts native <div> attributes, plus className, style and ref.
Popover.Content
| Prop | Type | Default |
|---|---|---|
childrenThe popover's content: usually a | ReactNode | — |
aria-labelAccessible name. Required when there is no | string | — |
initialFocusElement to focus when the popover opens: an element, a ref, or a function. A function runs after the content has rendered and been positioned, so it can pick a node inside the content (e.g. | FocusTarget | — |
initialFocusRefSame as | RefObject<HTMLElement | null> | — |
showArrowShow a pointer arrow on the side facing the anchor. | boolean | false |
showCloseShow a "Close" icon button in the top-end corner. | boolean | false |
closeLabelAccessible name of the | string | "Close" |
sizeWidth preset and padding: | "sm""md""lg" | "md" |
maxWidthCustom max width (any CSS length, or px as a number). Overrides the | CSSProperties["maxWidth"] | — |
containerElement to portal into. | HTMLElement | null | document.body |
Also accepts native <div> attributes, plus className, style and ref.
Popover.Title
| Prop | Type | Default |
|---|---|---|
levelHeading level. Pick it by document outline. | 23456 | 2 |
Also accepts native <h2> attributes, plus className, style and ref.
Popover.Description
Also accepts standard HTML attributes, plus className, style and ref.
Popover.Close
| Prop | Type | Default |
|---|---|---|
childrenButton label, or a single element to turn into the close control. | ReactNode | "Close" |
asChildClone the single child instead of wrapping it in a | boolean | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the label. Hidden from assistive technology. | ReactNode | — |
fullWidthStretches the button to fill its container. Inherits from a surrounding | boolean | false |
Also accepts native <button> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Popover targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| EnterSpace | On the trigger: opens or closes the popover. |
| Escape | Closes it and returns focus to the trigger. |
| Tab | Non-modal: from the last element, moves on to what follows the trigger and closes. Modal: wraps inside. |
| Shift+Tab | Non-modal: from the first element, returns to the trigger (stays open). |
Roles and states
| Element | Role | States and properties |
|---|---|---|
Popover.Content | dialog | aria-modal when modal, aria-labelledby → title, aria-describedby → description |
| Trigger | button | aria-haspopup="dialog", aria-expanded, aria-controls |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |