Skip to content

Now in the official shadcn registry directory.

Start free

Popover

A floating panel anchored to a trigger, rendered in a portal so it escapes overflow-hidden parents, with directional slide/zoom animations.

overlay
A free styled version is available

Installation

Run the following command

npx shadcn@latest add @ai2/popover

Dependencies, the @ai2/tokens theme and the component file are installed together.

Usage

TS
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"

<Popover>
  <PopoverTrigger asChild>
    <Button variant="outline">Open popover</Button>
  </PopoverTrigger>
  <PopoverContent>
    <p className="text-sm font-medium">Region status</p>
    <p className="text-sm text-muted-foreground">All 3 regions healthy.</p>
  </PopoverContent>
</Popover>

The content renders in a portal, so it escapes overflow-hidden parents. Use PopoverAnchor to position the panel against an element other than the trigger.

Examples

Alignment

Sizes

Custom width and offset

Props

PopoverContent sets these defaults; every part also forwards its underlying radix props - e.g. open / onOpenChange on Popover and side on PopoverContent.

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Panel width preset: sm is w-56, md is w-72, lg is w-80.
align"start" | "center" | "end""center"Alignment of the panel relative to the trigger.
sideOffsetnumber6Gap in pixels between the trigger and the panel.

ai2 Popover: an anchored floating panel for React

The ai2 Popover is a shadcn-compatible popover component for React, built on the radix-ui Popover primitive and styled with Tailwind CSS v4. It anchors a floating panel to a trigger, renders it in a portal so it escapes overflow-hidden parents and stacking contexts, and animates open and close with a directional fade, zoom and slide that always matches the side the panel opens from.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Popover?

It is a four-part composition: Popover, PopoverTrigger, PopoverContent and PopoverAnchor. The anatomy matches shadcn/ui exactly, so existing snippets, muscle memory and AI agents keep working without changes.

The content defaults to a 288px panel centered on the trigger with a 6px gap, and every radix Content prop is forwarded, so side, align, sideOffset and the collision options are one prop away. When the trigger is not the right reference point, PopoverAnchor positions the panel against any other element.

Why use it

  • Anchored positioning with collision handling: The radix-ui positioning engine keeps the panel attached to its trigger and flips it to the opposite side when it would leave the viewport, with no positioning code on your side.
  • Portal rendering: The panel renders in a portal at the document root, so it escapes overflow-hidden parents, table cells and transformed ancestors that break absolutely positioned menus.
  • Focus and dismiss behavior: Escape and outside clicks close the panel, focus returns to the trigger on close, and the trigger reports its state through aria-expanded. All of it comes from the radix primitive.
  • Direction-aware motion: The panel fades, zooms and slides in from the side it opens on, driven by data-state and data-side attributes, so the animation always matches the actual placement.
  • Agent-readable metadata: The registry item describes its parts and intended use in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component, its dependencies and the @ai2/tokens theme to your project.
  • PopoverAnchor part: Anchor the panel to an element other than the trigger, useful for toolbars, text selections and input adornments.
  • Sensible defaults, full override: align defaults to center, sideOffset to 6 and size to md (w-72); all are plain props, and a size of sm (w-56) or lg (w-80) swaps the width without touching className.
  • Anchor-based transform origin: The zoom animation originates from the radix transform-origin variable, so the panel grows out of the trigger instead of scaling from its own center.
  • Data attributes for styling: The panel exposes data-slot, data-state and data-side, so you can restyle open, closed and per-side appearance from CSS without forking the component.
  • TypeScript source: The file you install is typed end to end and forwards every radix prop, so autocomplete covers the full API including open, onOpenChange, side and modal.

Production tips

  • Use asChild on the trigger: Wrap an ai2 Button with PopoverTrigger asChild so the trigger keeps button styling and semantics instead of nesting two interactive elements.
  • Size the panel for its content: The size prop steps the width in three presets (sm w-56, md w-72, lg w-80). For anything outside that scale, override with className, and prefer a max-height with scrolling over a panel taller than the viewport.
  • Adjust spacing with sideOffset: Change the trigger-to-panel gap with sideOffset instead of margins; margins on the content interfere with the positioning engine.
  • Pick the right overlay: Use Popover for rich interactive content, DropdownMenu for a list of actions, and Tooltip for short hover-only hints. Screen reader behavior differs between the three.
  • Test near viewport edges: Collision handling flips the panel and updates data-side. If you add custom per-side styling, open the popover at the bottom and edges of the screen to verify both placements.

Works with the rest of ai2

The popover composes naturally with the rest of the registry. Wrap an ai2 Button as the trigger, build compact settings panels with ai2 Field rows inside the content, or combine it with ai2 Command to build searchable pickers.

For neighboring patterns, the ai2 Combobox is exactly this popover plus command list wired together, and ai2 Tooltip covers the hover-only cases where a popover would be too heavy. Everything shares one token source, so combinations stay visually consistent in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components