Components

Popover

A panel anchored to a button, for a short form, a picker or a few details: a share link, an estimate, a date.

Usage

import {
  Popover,
  PopoverContent,
  PopoverTitle,
  PopoverTrigger,
} from 'nyctoui/popover'

<Popover>
  <PopoverTrigger render={<Button />}>Share</PopoverTrigger>
  <PopoverContent>
    <PopoverTitle>Share issue</PopoverTitle>
    …
  </PopoverContent>
</Popover>

The popover opens on click, moves focus inside, and closes on Escape or a click outside, returning focus to the trigger. The page behind stays usable. For a choice from a list, use a Dropdown or a Select; for a label on hover, a Tooltip.

The content stacks its children 12px apart inside 12px of padding and sizes to fit them, up to 360px. Set a width through sx.

Good for

  • A Share popover with a link and a Copy button.
  • A quick filter form above a table, such as a date range and a status.
  • An info icon beside a metric in a dashboard, explaining how it’s worked out.
  • A “Snooze until” picker in an email client.

Anatomy

<Popover>
  <PopoverTrigger />
  <PopoverContent>
    <PopoverHeader>
      <PopoverTitle />
      <PopoverDescription />
      <PopoverCloseButton />
    </PopoverHeader>
    <PopoverFooter>
      <PopoverClose />
    </PopoverFooter>
  </PopoverContent>
</Popover>

Examples

Form

Control open to close the popover once the form is saved. Escape and PopoverClose cancel.

Infotip

For an explanation behind an info icon, add openOnHover to the popover. Unlike a tooltip, it still opens on tap and its text reaches screen readers.

Best practices

Do
  • Keep a popover to one small task or one piece of information.
  • Give it a clear way to close: a click outside, Escape, and a PopoverClose button when it holds a form.
  • Use openOnHover for an info icon, so it opens on hover and still opens on tap.
Don’t
  • Open a popover from inside another popover.
  • Use a popover to pick from a list. That’s a select or a dropdown.
  • Fill it with a long form. If it needs scrolling, use a dialog or a drawer.

API reference

Popover

Holds the open state. Renders no element.

PropTypeDefault
defaultOpen
Starts open. For uncontrolled use.
booleanfalse
open
Whether the popover is open. For controlled use.
boolean—
onOpenChange
Called when the popover opens or closes.
(open: boolean, details) => void—
onOpenChangeComplete
Called once the open or close animation has finished.
(open: boolean) => void—
modal
Traps focus, locks page scroll and blocks the page. trap-focus keeps only the focus trap.
boolean | 'trap-focus'false
openOnHover
Also opens on hover, for an infotip.
booleanfalse
delay
Milliseconds of hover before opening, with openOnHover.
number—

PopoverTrigger

The button that opens the popover. Renders a <button>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—

PopoverContent

The panel. Renders a <div> in the top layer.

PropTypeDefault
side
Which side of the trigger to open on. Flips when it would clip.
'top' | 'right' | 'bottom' | 'left''bottom'
align
How to line up with the trigger along that side.
'start' | 'center' | 'end''start'
sideOffset
Gap between the trigger and the panel, in pixels.
number6
alignOffset
Shift along the alignment axis, in pixels.
number0
anchor
Positions against another element than the trigger.
Element | string | { x, y } | null—
initialFocus
The element to focus on open. Defaults to the first focusable one.
'auto' | 'content' | 'none' | string | Element | function—
finalFocus
The element to focus on close. Defaults to the trigger.
'none' | string | Element | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PopoverHeader

Lays out the title, description and close button. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PopoverTitle

Labels the popover. Renders an <h2>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PopoverDescription

Describes the popover to assistive tech. Renders a <p>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PopoverFooter

Actions aligned to the end. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

PopoverClose

Closes the popover. Renders a <button>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—

PopoverCloseButton

A ghost icon Button with an X that closes the popover.

PropTypeDefault
aria-label
The accessible name of the button.
string'Close'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—