Skip to content

Popover

A panel attached to a button, for a share link, a filter or a small form. It sits in the top layer, so overflow, transforms and z-index on any ancestor cannot trap it, and it is placed with CSS anchor positioning where the browser has it, falling back to measuring in JavaScript. Focus moves in on open; Escape gives it back to the trigger, a click elsewhere leaves it where you put it. It springs out of whichever side it lands on.

  • Popover API
  • CSS anchor positioning
  • Spring Physics
  • Focus management

This card clips its overflow, scrolls, and is rotated. A menu positioned inside it would be cut off. The popover sits in the top layer, so it is not.

Projects

This browser does not support anchor positioning, so the filter uses JavaScript.

    Usage

    Drop it in

    import
    import { Popover } from "@/app/lib/components/popover";
    example 1
    <Popover label="Share" trigger={<button>Share</button>}>
      {(close) => <CopyLink onCopied={close} />}
    </Popover>

    API

    Props

    PropTypeDefault
    trigger*

    The control that opens it, usually a button. It gets aria-expanded, aria-haspopup and aria-controls.

    ReactElement—
    children*

    What it holds. Pass a function to get a `close` you can call from inside.

    ReactNode | ((close: () => void) => ReactNode)—
    label*

    Accessible name for the panel, read when focus moves into it.

    string—
    side

    Preferred side. It flips when there is no room. Default: "bottom"

    Side"bottom"
    align

    Alignment along the trigger. Default: "start"

    Align"start"
    offset

    Gap from the trigger in px. Default: 8

    number8
    open

    Controlled open state. Leave undefined to let it manage itself.

    boolean—
    onOpenChange

    Called whenever it opens or closes.

    (open: boolean) => void—
    positioning

    "auto" uses CSS anchor positioning where the browser has it, "js" always measures. Default: "auto"

    Positioning"auto"
    classNamestring""

    Read from the component's source at build time. * required.

    Accessibility

    Works with

    Cursor
    Reacts to where the pointer is, not just whether it's over the element.
    Touch
    Follows your finger while it's down, then settles a moment after you lift.
    Keyboard
    Focus lights it up the way the cursor does. Every action has a key.
    Reduced motion
    Nothing moves or springs. Colour still answers, without drifting.