Skip to main content

popover

Displays rich content in a floating layer, triggered by an anchor element.

About

Popover built with @floating-ui/react and Popper-based primitives for collision-aware positioning.

Philosophy

Popovers bridge the gap between tooltips (hover, no interaction) and dialogs (heavy, blocking). They're the right choice for inline forms, color pickers, and contextual actions that need more space than a tooltip but shouldn't interrupt the user's flow. We handle positioning and collision detection so you can focus on content.

How It's Built

Loading diagram...

Installation


npx @gentleduck/cli add popover

npx @gentleduck/cli add popover

Usage

import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"
<Popover>
  <PopoverTrigger>Open</PopoverTrigger>
  <PopoverContent>Place content for the popover here.</PopoverContent>
</Popover>
<Popover>
  <PopoverTrigger>Open</PopoverTrigger>
  <PopoverContent>Place content for the popover here.</PopoverContent>
</Popover>

Examples

Sides

Form

Active Trigger on Open

Style the trigger to appear active while the popover is open using data-[state=open]:

Component Composition

Loading diagram...

RTL Support

Set dir="rtl" on Popover for a local override, or set DirectionProvider once at app/root level for global direction. In RTL mode, side="left" and side="right" are logically swapped.

<Popover dir="rtl">
  <PopoverTrigger>افتح</PopoverTrigger>
  <PopoverContent>محتوى النافذة المنبثقة هنا.</PopoverContent>
</Popover>
<Popover dir="rtl">
  <PopoverTrigger>افتح</PopoverTrigger>
  <PopoverContent>محتوى النافذة المنبثقة هنا.</PopoverContent>
</Popover>

Motion

Use MotionPopover and MotionPopoverContent for smooth enter/exit animations powered by motion. The transform origin matches the placement side automatically.

API Reference

Popover

PropTypeDefaultDescription
childrenReact.ReactNode-Popover sub-components (PopoverTrigger, PopoverContent)
defaultOpenboolean-Initial open state for uncontrolled usage
openboolean-Controlled open state
onOpenChange(open: boolean) => void-Callback when open state changes
modalbooleanfalseEnables modal focus/interaction behavior
dir'ltr' | 'rtl'-Text direction. Resolved by primitives useDirection (dir prop -> DirectionProvider -> 'ltr').
...propsReact.ComponentPropsWithoutRef<typeof PopoverPrimitive.Root>-Additional props inherited from Popover.Root.

PopoverTrigger

PropTypeDefaultDescription
asChildboolean--Use the child element as the trigger
...propsReact.ComponentPropsWithoutRef<typeof PopoverPrimitive.Trigger>-Additional props inherited from Popover.Trigger.

PopoverContent

PropTypeDefaultDescription
forceMountboolean-Keep content mounted for animation control
side'top' | 'right' | 'bottom' | 'left''bottom'Preferred side relative to the trigger
align'start' | 'center' | 'end''center'Alignment on the chosen side
sideOffsetnumber4Main-axis offset from trigger
alignOffsetnumber0Cross-axis offset from trigger
...propsReact.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>-Additional props inherited from Popover.Content.

PopoverClose

Element that closes the popover when interacted with.

PropTypeDefaultDescription
asChildbooleanfalseRenders child as the close control
childrenReact.ReactNode-Close control content
...propsReact.ComponentPropsWithoutRef<typeof PopoverPrimitive.Close>-Additional props inherited from PopoverPrimitive.Close

PopoverAnchor

Optional custom anchor element for positioning.

PropTypeDefaultDescription
...propsReact.ComponentPropsWithoutRef<typeof PopoverPrimitive.Anchor>-Additional props inherited from Popover.Anchor.

MotionPopover

Wraps with useMotionRoot for exit animation support. Requires the motion package.

PropTypeDefaultDescription
...propsPopoverProps-All props from Popover are supported

MotionPopoverContent

Adds scale, blur, and opacity enter/exit animation with springBouncy transition. Requires the motion package.

PropTypeDefaultDescription
...propsPopoverContentProps-All props from PopoverContent are supported