Blocks Design System

Popover

A non-modal panel anchored to its trigger, on Base UI Popover: extra detail or a few controls next to the thing they describe. The page stays usable behind it. Use Modal for a task that needs the reader’s full attention, and Tooltip for a short label.

tsx
import { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger } from '@blocks/design-system'

From a Server Component, import the parts by name; client-authored code can use Popover.Trigger and the rest.

Usage

PopoverTitle names the popover and PopoverDescription describes it. side, align and sideOffset on PopoverContent place it; it flips to stay in the viewport.

Source · popover/named-parts.tsx
popover/named-parts.tsx
// A Server Component: named parts, default portal.
import { Button, Popover, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger } from '@blocks/design-system'

export default function NamedParts() {
  return (
    <Popover>
      <PopoverTrigger render={<Button type="button" variant="ghost" />}>What is SWE?</PopoverTrigger>
      <PopoverContent side="top">
        <PopoverTitle>Snow water equivalent</PopoverTitle>
        <PopoverDescription>The depth of water the snowpack would make if it all melted at once.</PopoverDescription>
      </PopoverContent>
    </Popover>
  )
}
A definition

Themes and portals

The popover renders at the end of document.body. Inside a subtree with its own data-ds-theme, pass container with an element in that subtree. Each Popover keeps its own open state.

  • Mount Hood
  • Alta
Source · popover/station-details.tsx
popover/station-details.tsx
'use client'

import { Box, Button, Popover, Stack } from '@blocks/design-system'
import { useState } from 'react'

const stations = [
  { id: 'mount-hood', name: 'Mount Hood', detail: 'Snow pillow at 5,370 ft, reporting hourly.' },
  { id: 'alta', name: 'Alta', detail: 'Snow pillow at 8,760 ft, reporting every 15 minutes.' },
]

// The list forces a dark theme; each popover mounts inside it.
export default function StationDetails() {
  const [panel, setPanel] = useState<HTMLElement | null>(null)
  return (
    <Box as="section" ref={setPanel} data-ds-theme="dark" aria-label="Stations" padding="md" backgroundColor="bg" color="text">
      <Stack as="ul" gap="sm" margin="none" padding="none">
        {stations.map((station) => (
          <Stack as="li" key={station.id} direction="row" justify="space-between" align="center" dangerouslySetStyle={{ listStyle: 'none' }}>
            <span>{station.name}</span>
            <Popover>
              <Popover.Trigger render={<Button type="button" size="sm" variant="ghost" />}>{station.name} details</Popover.Trigger>
              <Popover.Content container={panel} side="bottom" align="end">
                <Popover.Title>{station.name}</Popover.Title>
                <Popover.Description>{station.detail}</Popover.Description>
                <Popover.Close render={<Button type="button" size="sm" />}>Done</Popover.Close>
              </Popover.Content>
            </Popover>
          </Stack>
        ))}
      </Stack>
    </Box>
  )
}
Station details

Dismissal

Escape, a click outside, or a PopoverClose closes the popover, and focus returns to its trigger.

Props

Popover props
PropTypeDefaultDescription
actionsRefRefObject<PopoverRootActions | null>—A ref to imperative actions. - `unmount`: Manually unmounts the popover. Call this after any externally controlled closing animation finishes. - `close`: Closes the popover imperatively when called.
childrenReactNode | PayloadChildRenderFunction<unknown>—The content of the popover. This can be a regular React node or a render function that receives the `payload` of the active trigger.
defaultOpenbooleanfalseWhether the popover is initially open. To render a controlled popover, use the `open` prop instead.
defaultTriggerIdstring | null—ID of the trigger that the popover is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open popover.
handlePopoverHandle<unknown>—A handle to associate the popover with a trigger. If specified, allows external triggers to control the popover's open state.
modalboolean | "trap-focus"falseDetermines if the popover enters a modal state when open. - `true`: user interaction is limited to the popover: document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. - `'trap-focus'`: focus is trapped inside the popover, but document page scroll is not locked and pointer interactions outside of it remain enabled. On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. When `modal` is `true`, focus trapping is enabled only if `<Popover.Close>` is rendered inside `<Popover.Popup>`. It can be visually hidden with your own CSS if needed, such as Tailwind's `sr-only` utility. When `modal` is `'trap-focus'`, render `<Popover.Close>` inside `<Popover.Popup>` so touch screen readers can escape the popup.
onOpenChange((open: boolean, eventDetails: PopoverRootChangeEventDetails) => void)—Event handler called when the popover is opened or closed.
onOpenChangeComplete((open: boolean) => void)—Event handler called after any animations complete when the popover is opened or closed.
openboolean—Whether the popover is currently open.
triggerIdstring | null—ID of the trigger that the popover is associated with. This is useful in conjunction with the `open` prop to create a controlled popover. There's no need to specify this prop when the popover is uncontrolled (that is, when the `open` prop is not set).
PopoverTrigger props
PropTypeDefaultDescription
closeDelaynumber0How long to wait before closing the popover that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
delaynumber300How long to wait before the popover may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
handlePopoverHandle<unknown>—A handle to associate the trigger with a popover.
nativeButtonbooleantrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
openOnHoverbooleanfalseWhether the popover should also open when the trigger is hovered.
payloadunknown—A payload to pass to the popover when it is opened.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.

PopoverContent props
PropTypeDefaultDescription
align"center" | "start" | "end"'center'How to align the popup relative to the specified side.
containerPortalContainer—Where the popup mounts. Defaults to `document.body`; pass an element inside a `data-ds-theme` subtree so the popup inherits its theme.
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)—Determines the element to focus when the popover is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
initialFocusboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)—Determines the element to focus when the popover is opened. By default, focus moves to the first tabbable element inside the popup, except when the popover is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (first tabbable element or popup). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverPopupState>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
side"top" | "bottom" | "left" | "right" | "inline-end" | "inline-start"'bottom'Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
sideOffsetnumber | OffsetFunction0Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} /> ```

Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.

PopoverTitle props
PropTypeDefaultDescription
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTitleState>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.

PopoverDescription props
PropTypeDefaultDescription
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverDescriptionState>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.

PopoverClose props
PropTypeDefaultDescription
nativeButtonbooleantrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverCloseState>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.

Accessibility

  • Give every popover a PopoverTitle; it is announced as the dialog’s name when it opens.
  • The trigger is a button that announces whether the popover is expanded.
  • Keep content short. Don’t hide information people need to finish a task inside a popover.