Popover

React Popover components display floating content anchored to a trigger element. They are commonly used for contextual information, settings panels, and inline actions that don’t require full navigation.

This Popover component is built with React and styled using Tailwind CSS. It uses Floating UI for positioning and provides accessible focus and keyboard handling.

Installation

Usage

Import the popover components and wrap a trigger with content.

import {
  Popover,
  PopoverTrigger,
  PopoverContent,
  PopoverHeading,
  PopoverDescription,
  PopoverClose
} from "@/registry/core/popover";

export default function Example() {
  return (
    <Popover>
      <PopoverTrigger>Open Popover</PopoverTrigger>

      <PopoverContent>
        <PopoverHeading>Popover Title</PopoverHeading>
        <PopoverDescription>
          This is a short description inside the popover.
        </PopoverDescription>

        <PopoverClose className="mt-4 text-sm underline">Close</PopoverClose>
      </PopoverContent>
    </Popover>
  );
}

Examples

Default

Basic popover with heading and description.

<Popover>
  <PopoverTrigger>Options</PopoverTrigger>
  <PopoverContent>
    <PopoverHeading>Settings</PopoverHeading>
    <PopoverDescription>Manage only the settings you need.</PopoverDescription>
  </PopoverContent>
</Popover>

With Close Button

Include a close action inside the popover content.

<Popover>
  <PopoverTrigger>Details</PopoverTrigger>
  <PopoverContent>
    <PopoverHeading>Profile</PopoverHeading>
    <p className="text-sm">Edit your personal information.</p>

    <PopoverClose className="mt-4 text-sm underline">Close</PopoverClose>
  </PopoverContent>
</Popover>

Controlled Open State

Control the open state using React state.

const [open, setOpen] = useState(false);

<Popover open={open} onOpenChange={setOpen}>
  <PopoverTrigger>Toggle</PopoverTrigger>
  <PopoverContent>
    <p>This popover is fully controlled.</p>
  </PopoverContent>
</Popover>;

Custom Placement

Change the popover position relative to the trigger.

<Popover placement="right-start">
  <PopoverTrigger>Right Popover</PopoverTrigger>
  <PopoverContent>Content positioned on the right.</PopoverContent>
</Popover>

API Reference

Popover

PropTypeDefaultDescription
initialOpenbooleanfalseInitial uncontrolled open state
openbooleanControlled open state
onOpenChange(open: boolean) => voidCalled when open state changes
placementPlacement (@floating-ui)"bottom"Position of popover relative to trigger
modalbooleanfalseTrap focus while open

PopoverTrigger

Wraps the clickable element that toggles the popover.

PropTypeDefaultDescription
asChildbooleanfalseUse any element as the trigger

PopoverContent

Floating panel element that contains the popover UI.

PropTypeDescription
styleReact.CSSPropertiesInline style merged with floating-ui positioning styles
refReact.Ref<HTMLDivElement>Used internally for positioning

PopoverHeading

  • Registers itself as the aria-labelledby for the popover.
  • Automatically binds/unbinds when mounted/unmounted.

PopoverDescription

  • Registers itself as aria-describedby for the popover.

PopoverClose

A convenience button that closes the popover when clicked.


Accessibility

  • Uses aria-labelledby and aria-describedby
  • Keyboard accessible with Tab, Arrow, Shift+Tab, and Escape
  • Focus is managed automatically when the popover opens and closes
  • Triggers expose data-state="open" | "closed"
  • Works with screen readers and assistive technologies
  • Supports modal focus trapping when enabled

Notes

  • Uses FloatingArrow for accurate arrow positioning
  • Supports both controlled and uncontrolled states
  • Automatically flips, shifts, and offsets using Floating UI middleware
  • asChild allows integrating with custom buttons (Radix-style)