How it works
A non-modal card opened by click: no backdrop, no focus trap, and it closes on outside click, Esc or tabbing out. The panel is borderless with a 20px radius, a hairline ring and a soft large shadow. It hangs under the trigger's wrapper with absolute positioning (no portal or fixed), so scroll areas and scaled containers keep it in place; ancestors that clip content count as boundaries and the panel flips when it does not fit. The stylesheet ships 36px pill buttons (ds-popover__btn with --primary ink, --secondary grey, --danger) for the content and the trigger; a secondary pill turns ink while its popover is open. The same file exports PopConfirm, which adds a tinted warning icon, a submit flow with a spinner and an in-place error.
Use it for
- Extra content seen on demand that includes clickable things: more details with a copy button, filters, sharing options.
- Light confirmation in table rows or cards (archive, remove from list) with PopConfirm, asking in place without covering the page.
- Small content (a few lines, two or three buttons) that does not deserve a dialog.
Look elsewhere when
- A single sentence that does not need clicking: use a tooltip.
- A list of actions to pick from: use a dropdown menu with arrow-key navigation.
- Irreversible, dangerous actions: use a modal confirmation dialog; PopConfirm is for light consequences.
- Long content or a form: use a modal or a side drawer.
Usage
import { Popover, PopConfirm } from './Popover.jsx'
// Popover: the card can hold clickable content; pass a function as content to get close
<Popover
title="Project info"
placement="bottom-start"
content={({ close }) => (
<>
<p>Last updated: today 09:12</p>
<button className="ds-popover__btn ds-popover__btn--secondary" onClick={close}>
Got it
</button>
</>
)}
>
<button className="ds-popover__btn ds-popover__btn--secondary">Details</button>
</Popover>
// PopConfirm: a light inline confirmation; with a Promise it shows loading and closes on success
<PopConfirm
tone="danger"
title="Archiving cancels 2 scheduled reviews"
confirmText="Archive"
onConfirm={() => archiveProject(project.id)}
>
<button className="ds-popover__btn ds-popover__btn--secondary">Archive</button>
</PopConfirm>Props
| Prop | Type | Default | What it does |
|---|---|---|---|
children | ReactElement | — | The trigger: one focusable element (button or link). The component wires up click toggling and aria-haspopup, aria-expanded and aria-controls. |
content | ReactNode | ({ close }) => ReactNode | — | Panel content: buttons, links, forms. A function receives close, to dismiss the popover after something inside is clicked. |
title | ReactNode | — | Optional title, also the accessible name of the panel. Without it, pass aria-label. |
placement | 'top' | 'bottom' | 'left' | 'right' (+ -start / -end) | 'bottom' | One of 12 positions. Flips to the opposite side when this one is too tight and the other has more room; pushed back when crossing the edge. |
arrow | boolean | true | Shows the small arrow pointing at the trigger. |
width | number | string | — | Panel width. By default it fits the content, up to 320px. |
open | boolean | — | Controlled: whether it is open. |
defaultOpen | boolean | false | Uncontrolled: whether it starts open. |
onOpenChange | (open) => void | — | Called when the open state changes. |
dismissible | boolean | true | When false, outside clicks, Esc, focus leaving and clicking the trigger do not close it; only close() or the parent does (use while submitting). |
initialFocus | RefObject | — | What to focus after opening. Defaults to the panel itself. |
disabled | boolean | false | Disables it: clicking the trigger does not open it, and no aria attributes are added. |
...rest | HTMLAttributes | — | className and other attributes go to the panel (the role=dialog element). |
PopConfirm · title | ReactNode | — | The question. State the consequence (“Archiving cancels 2 scheduled reviews”). |
PopConfirm · confirmText | ReactNode | — | Confirm button text. Required: name the action (“Archive”, “Remove”), not “OK”. |
PopConfirm · cancelText | ReactNode | 'Cancel' | Cancel button text. |
PopConfirm · tone | 'default' | 'danger' | 'default' | danger: danger-styled confirm button, and focus lands on Cancel. default: primary button, and focus lands on Confirm. |
PopConfirm · onConfirm | () => void | Promise | — | Called on confirm. A returned Promise shows loading, blocks closing, closes on success and shows the error text on failure; otherwise it closes at once. |
PopConfirm · onCancel | () => void | — | Called on Cancel; the popover then closes. |
PopConfirm · errorText | ReactNode | (error) => ReactNode | 'That did not work. Please try again.' | Text shown on failure. |
PopConfirm · labels | object | — | Replaces built-in text that has no prop of its own (working: the status read to screen readers while submitting). Shallow-merged over the English defaults. |
PopConfirm · others | placement / arrow / open / defaultOpen / onOpenChange / disabled / ...rest | — | Same as Popover; placement defaults to 'top'. |
Accessibility
- The trigger has aria-haspopup="dialog", aria-expanded and aria-controls; the panel is role="dialog" (non-modal, no aria-modal) named through aria-labelledby.
- Focus moves into the panel on open and Tab follows page order; tabbing out closes it.
- Esc closes and returns focus to the trigger; it is not propagated, so an enclosing dialog stays open. Clicking outside closes it.
- No hover dependence: it responds to click, Enter and Space, so touch works too.
- PopConfirm: for danger, focus lands on Cancel; while submitting, the confirm button has aria-busy and keeps focus, a screen-reader-only status says it is working, and failures appear in a role="alert" region.
- Pill buttons are 36px with a 44px hit area; reduced motion removes the scale and slide and only fades.
Motion
Opening grows from the arrow tip: scale 0.94 to 1 while sliding 6px away from the trigger, with a fade, 220ms ease-out. Closing is faster, 140ms ease-in, and unmounts afterwards. The error message expands in 240ms; pill buttons scale to 0.97 in 100ms when pressed. Reduced motion: fade only.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
Popover.jsxpopover.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

