oakoss/ui
Components

Popover

A panel anchored to a trigger, for content and controls that don't need a full dialog.

SourceReact Aria

Installation

npx shadcn@latest add @oakoss/popover

This also installs Dialog, whose parts Popover reuses, and Button.

Usage

import {
  Popover,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
} from '#/components/ui/overlays/popover';

<PopoverTrigger>
  <Button>Open</Button>
  <Popover>
    <PopoverHeader>
      <PopoverTitle>Title</PopoverTitle>
      <PopoverDescription>Description</PopoverDescription>
    </PopoverHeader>
  </Popover>
</PopoverTrigger>;

Examples

Arrow

showArrow draws an arrow that points at the trigger from any placement.

Scrolling body

PopoverBody scrolls tall content between the header and the panel's edge.

Accessibility

Popover wraps its content in React Aria's Dialog, so PopoverTitle names it. Like Dialog, the description isn't linked, so screen readers don't read a long popover in full when it opens; pass aria-describedby with the description's id to have a short one read. A popover without a title needs an aria-label.

React Aria moves focus into the popover on open, keeps it there, and returns it to the trigger on close. Escape and a click outside close it. start and end placements follow the locale's direction. Tall content without a control in it goes in PopoverBody, which keyboard users can focus to scroll.

The panel keeps a border in Windows High Contrast, where the arrow takes the system colors.

Follows the WAI-ARIA dialog pattern.

API

Popover

Renders React Aria's Popover with a Dialog inside. className applies to the panel. Its z-index is the z-(--z-popover) class, which a z-* class in className overrides; Popover clears the 100000 React Aria sets inline. A dialog opened from an open popover renders below it, so close the popover first.

Props

Prop

Type

Also accepts React Aria Popover props except isNonModal, since the dialog inside always contains focus; children and className take plain values, not render functions. placement defaults to bottom, and offset to 8, or 12 with an arrow. On a phone, a trigger in the middle of the screen leaves no room beside it, so prefer top or bottom over start and end there.

Data attributes

AttributePresent when
data-slotAlways: popover-content (the panel), popover (the dialog); popover-arrow with showArrow
data-placementAlways; the side the panel opened on (top, bottom, left, right)
data-enteringThe panel is fading in
data-exitingThe panel is fading out

PopoverHeader, PopoverTitle, PopoverDescription, PopoverBody, PopoverTrigger

Dialog's parts with popover-* data-slots (PopoverBody keeps dialog-body), sized for a popover.

PopoverContent

React Aria's Popover with Popover's look, motion, offset, z-index and showArrow, but no Dialog inside, for a popover that brings its own content, as Hover Card does. className wins over the panel's classes.

Props

Prop

Type

Also accepts all React Aria Popover props; placement and offset default as on Popover.

Data attributes

AttributePresent when
data-slotAlways: popover-content, or the data-slot passed in; popover-arrow with showArrow
data-placementAlways; the side the panel opened on (top, bottom, left, right)
data-enteringThe panel is fading in
data-exitingThe panel is fading out