本文へ移動
日本語

仕組み

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.

向いている場面

  • 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.

向かない場面

  • 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.

使い方

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>

プロパティ

プロパティ型既定値説明
childrenReactElement—The trigger: one focusable element (button or link). The component wires up click toggling and aria-haspopup, aria-expanded and aria-controls.
contentReactNode | ({ close }) => ReactNode—Panel content: buttons, links, forms. A function receives close, to dismiss the popover after something inside is clicked.
titleReactNode—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.
arrowbooleantrueShows the small arrow pointing at the trigger.
widthnumber | string—Panel width. By default it fits the content, up to 320px.
openboolean—Controlled: whether it is open.
defaultOpenbooleanfalseUncontrolled: whether it starts open.
onOpenChange(open) => void—Called when the open state changes.
dismissiblebooleantrueWhen false, outside clicks, Esc, focus leaving and clicking the trigger do not close it; only close() or the parent does (use while submitting).
initialFocusRefObject—What to focus after opening. Defaults to the panel itself.
disabledbooleanfalseDisables it: clicking the trigger does not open it, and no aria attributes are added.
...restHTMLAttributes—className and other attributes go to the panel (the role=dialog element).
PopConfirm · titleReactNode—The question. State the consequence (“Archiving cancels 2 scheduled reviews”).
PopConfirm · confirmTextReactNode—Confirm button text. Required: name the action (“Archive”, “Remove”), not “OK”.
PopConfirm · cancelTextReactNode'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 · errorTextReactNode | (error) => ReactNode'That did not work. Please try again.'Text shown on failure.
PopConfirm · labelsobject—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 · othersplacement / arrow / open / defaultOpen / onOpenChange / disabled / ...rest—Same as Popover; placement defaults to 'top'.

アクセシビリティ

  • 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.

モーション

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.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

Popover.jsxpopover.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

オーバーレイ
「ボトムシート」は Pro に含まれます。解除するとプレビューが表示されます。