Todae

Todae

Popover

usePopover is the open machine. Spread getTriggerProps on the trigger. Spread getPopoverProps on Popover.Root. Popover.Root is surface chrome only: children, className, style, and, with role="dialog", an accessible name. There is no Popover.Trigger or Popover.Content. ARIA prohibits a name on an element with no role, so a role-less popover takes none: the type rejects aria-label and aria-labelledby there, and the element drops them. Name what is inside instead, such as the OptionList.Root of a menu or combobox. With role="dialog", the type requires aria-label or aria-labelledby.

On this page

haspopup sets the trigger's aria-haspopup: dialog by default, listbox for an OptionList in a role-less popover, menu for an action menu. For action menus, use Menu.

Non-modal popover="manual". Outside click and Escape call onOpenChange(false, reason). hidePopover() runs only after open is false, so a veto keeps it shown.

The surface is always in the page, so ids that point at it resolve, but what it holds mounts on the first open and stays mounted after it. A page of closed comboboxes, chip lists and coachmarks renders none of their content until one opens, and the content keeps its state between opens. Code or tests that read the content before the first open should open the popover first, and a form around a popover that never opened does not submit the fields inside it.

No focus trap, no aria-modal, no scroll lock, and no inert while open. No portal — the surface stays in the React tree so ThemeProvider vars inherit.

Positioning is CSS anchors only. getTriggerProps sets anchor-name. anchorRef does the same when the trigger is not the anchor (Combobox Field). Content uses position-anchor and top: calc(anchor(bottom) + var(--todae-popover-offset)). The gap is the popover.offset token (--todae-popover-offset), which points at space.1 (0.25rem). Flip is position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline. There is no JS pin, no getBoundingClientRect follow, and no rAF scroll glue.

A browser without CSS anchors does not place the surface next to its trigger. The surface resets the UA popover centering, so it sits near the top-left corner of the viewport, and it does not follow scroll or flip. Todae does not polyfill that. Safari 26+ has anchors. Chrome, Firefox and Safari 26 flip with the flip-block tactic. iOS before 26 has popover and no CSS anchors.

The surface is the top-layer hit target: position: fixed; inset: unset; pointer-events: auto. Taps on content do not pass through. OptionList.Option selects on click so closing the list cannot leave a leftover click on the page.

The surface fades in while it grows from popover.motion.scale (96%, or 90% in the expressive motion preset) out of the corner of its trigger, and fades and shrinks back as it closes, with the popover.motion.* duration and easing tokens. Menu opens and closes the same way, and the field pickers open the same way and go at once as they close. It moves the same way in Safari. While it closes it stays drawn but is inert, so no press or focus lands in it, and content that resets on close, such as a Drilldown, resets once the fade ends. A tooltip whose trigger is inside waits for the growth to settle before it opens, since it is placed against the trigger's unscaled box. Under reduced motion it only fades.

A brand can also slide it in from its trigger: popover.motion.offset (0 by default) is how far toward the trigger it starts as it opens and ends as it closes; a submenu beside its menu only fades and grows. It moves by layout, not a transform, so a tooltip inside stays by its trigger. Under reduced motion it doesn't slide.

Examples

A fruit picker: usePopover opens a Popover.Root that holds an option list.

import { Button, OptionList, Popover, Stack, usePopover } from '@tounsoo/todae';
import { useState } from 'react';

export default function PopoverMenu() {
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState<string | null>(null);
  const [under, setUnder] = useState(0);
  const popover = usePopover({ open, onOpenChange: setOpen, haspopup: 'listbox' });
  return (
    <Stack.Root>
      <Button.Root tooltip={false} {...popover.getTriggerProps()}>
        {value ? `Fruit: ${value}` : 'Choose fruit'}
      </Button.Root>
      <Popover.Root {...popover.getPopoverProps()}>
        <OptionList.Root
          aria-label="Fruit"
          value={value}
          onValueChange={(next) => {
            setValue(next);
            setOpen(false);
          }}
        >
          <OptionList.Option value="apple">Apple</OptionList.Option>
          <OptionList.Option value="pear">Pear</OptionList.Option>
          <OptionList.Option value="plum">Plum</OptionList.Option>
        </OptionList.Root>
      </Popover.Root>
      <Button.Root variant="secondary" onClick={() => setUnder((count) => count + 1)}>
        Page under {under}
      </Button.Root>
    </Stack.Root>
  );
}

Veto outside clicks. Escape still closes. onOpenChange still receives reason so Combobox and this veto can ignore outside.

import { Button, Popover, Stack, usePopover } from '@tounsoo/todae';
import { useState } from 'react';

export default function PopoverVeto() {
  const [open, setOpen] = useState(false);
  const popover = usePopover({
    open,
    onOpenChange: (next, reason) => {
      if (reason === 'outside') return;
      setOpen(next);
    },
  });
  return (
    <>
      <Button.Root tooltip={false} {...popover.getTriggerProps()}>
        Outside is vetoed
      </Button.Root>
      <Popover.Root {...popover.getPopoverProps()} role="dialog" aria-label="Pinned">
        <Stack.Root>
          Outside click calls onOpenChange but this stays open. Escape still closes.
          <Button.Root variant="secondary" onClick={() => setOpen(false)}>
            Close
          </Button.Root>
        </Stack.Root>
      </Popover.Root>
    </>
  );
}

anchorRef is the CSS anchor when the trigger is not the element getTriggerProps marks. It also excludes that element from outside dismiss. Do not spread getTriggerProps and also pass anchorRef — dual-wire is a QA fail.

Selecting in OptionList does not close the popover. The fruit demo closes on single select in the consumer.

What goes where

ConcernAPI
Behavior

usePopover — open / defaultOpen / onOpenChange, haspopup, anchorRef, focus refs, enabled, id

Chrome

Popover — children, className, style, accessible name

Accessible composition

Todae handles: getTriggerProps sets aria-expanded, aria-controls and aria-haspopup; the surface is always mounted, so aria-controls always points at it. On open, focus moves to initialFocusRef, else the first tabbable element inside, else the surface itself. Escape and an outside press ask to close. On close, focus goes to restoreFocusRef, else back to what had focus before it opened, unless the person already moved it elsewhere. With role="dialog" the type requires a name, and Todae never sets aria-modal. When the surface scrolls past its max height, arrows show at the cut-off edges and scroll while a pointer rests on them, as on ScrollArea; they are hidden from assistive technology and never take focus, and arrows={false} turns them off.

You supply: A trigger that is a real button, such as Button.Root: getTriggerProps adds onClick and ARIA, not a role, a tab stop or key handling. A haspopup that matches what opens: dialog with role="dialog" and a name on Popover.Root, or listbox with a named OptionList.Root in a role-less popover. For an action menu, use Menu.

Watch for: A role-less popover left on the default haspopup tells screen readers a dialog opened when none did. Pass your own onClick and ref through getTriggerProps(props): put after the spread, they replace the hook's. There is no focus trap, and Tab can move out while the popover stays open, so don't use it for work that must keep focus; that is a Dialog.

When to use

When: Non-modal anchored surface (listbox pickers, Combobox desktop list, light panels). Use usePopover + surface-only Popover — open/dismiss on the hook, chrome on the surface. Outside click + Escape dismiss. No focus trap.

When not: Action menu → Menu. Modal / focus-trapped work → Dialog. Mobile full-bleed picker → BottomSheet. Text-only hover hint → Tooltip.

Props

The open machine's props are on usePopover.

Popover.Root props
NameTypeDescription
arrowsboolean

Whether an arrow shows at its top or bottom edge while what it holds is cut off there. Resting a mouse or pen on one scrolls toward it. On by default, as a popover holds its list and scrolls past its max height.

Default: true

childrenReact.ReactNode

Popover contents. Mounted on the first open, and kept after it.

classNamestring

Class name for the surface.

style RequiredReact.CSSProperties

Style for the surface. Anchor position comes from getPopoverProps.

aria-labelstring

Accessible name when no visible caption exists. Only with role="dialog"; a role-less popover drops it, so name its contents instead.

aria-labelledbystring

Id of the visible caption. Only with role="dialog"; a role-less popover drops it.

role"dialog"

Non-modal dialog role. Requires aria-label or aria-labelledby. Does not set aria-modal.