When to use
- A small task next to the thing it acts on: sharing a document, renaming a file, setting a reminder.
- A short form or a few controls that should not take people off the page: invite by email, pick a due date.
- Detail that people open on purpose and that can hold buttons and links, which a tooltip cannot.
When not to use
- A one-line label for an icon button: use a Tooltip.
- A list of actions or options to choose from: use a Dropdown Menu or a Select.
- A decision that must be made before people carry on, or a long form: use a Dialog.
Installation
pnpm dlx shadcn add https://eased.dev/r/popover.jsonnpx shadcn add https://eased.dev/r/popover.jsonyarn dlx shadcn add https://eased.dev/r/popover.jsonbunx --bun shadcn add https://eased.dev/r/popover.jsonThe command adds Popover, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/reactAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/popover/popover.tsxTSX "use client";import { Popover as BasePopover } from "@base-ui/react/popover";import type { ComponentProps, ReactNode } from "react";import { FloatingLayer, floatingSurface, type FloatingAlign, type FloatingMotion, type FloatingSide,} from "../_primitives/floating/floating";import { Button, type ButtonSize, type ButtonVariant } from "../button/button";/** * Groups a popover's parts and owns its open state. Uncontrolled by default (`defaultOpen`); * pass `open` and `onOpenChange` to control it. Non-modal unless `modal` is set. */export const Popover = BasePopover.Root;/** Closes the popover. Use `render` to make any button a closer: `<PopoverClose render={<button … />} />`. */export const PopoverClose = BasePopover.Close;export type PopoverTriggerProps = Omit<ComponentProps<typeof BasePopover.Trigger>, "className"> & { /** The Eased `Button` variant. Default "secondary". */ variant?: ButtonVariant; /** The Eased `Button` size. Default "sm" (32px); `icon-sm` for a square icon trigger. */ size?: ButtonSize; className?: string;};/** * The button that opens the popover: an Eased `Button`, which never scales as a popup * trigger (R64) so the popup's transform-origin stays fixed, and stays pressed (`aria-expanded`) * while the popover is open. Pass `render` to bring your own trigger (style it with * `floatingTrigger`). `openOnHover`, `delay` and `closeDelay` turn it into a hover-intent trigger. */export function PopoverTrigger({ variant = "secondary", size = "sm", className = "", render, ...props }: PopoverTriggerProps) { return <BasePopover.Trigger {...props} render={render ?? <Button variant={variant} size={size} className={className} />} />;}export type PopoverContentProps = { /** Preferred side; flips on collision and the enter direction follows. Default "bottom". */ side?: FloatingSide; /** Default "center". */ align?: FloatingAlign; /** Gap to the trigger, px. Default 6. */ sideOffset?: number; alignOffset?: number; /** Override the floating motion (distance, scale, fade, exit). */ motion?: Partial<FloatingMotion>; /** Where focus goes on open. Default: the first tabbable element, else the popup. */ initialFocus?: ComponentProps<typeof BasePopover.Popup>["initialFocus"]; /** Where focus returns on close. Default: the trigger. */ finalFocus?: ComponentProps<typeof BasePopover.Popup>["finalFocus"]; container?: HTMLElement | null; /** Stacking order. Default 50; raise it inside a higher layer such as a dialog. */ zIndex?: number; /** Appended to the panel's classes; set a width here (default `w-80`, never wider than the viewport). */ className?: string; children?: ReactNode;};/** * The panel. It opens from the trigger's transform-origin with a 5px offset toward the * trigger, and leaves half as far in 150ms. Open and close are transitions, so they reverse * mid-flight. A raised 16px panel with 16px padding; `--radius-outer` and `--pad` are exposed so * nested corners (see `PopoverFooter`) stay concentric. */export function PopoverContent({ side = "bottom", align = "center", sideOffset, alignOffset, motion, initialFocus, finalFocus, container, zIndex, className = "", children,}: PopoverContentProps) { return ( <FloatingLayer parts={BasePopover} role="popover" side={side} align={align} sideOffset={sideOffset} alignOffset={alignOffset} motion={motion} container={container} zIndex={zIndex} popupProps={{ initialFocus, finalFocus }} className={`${floatingSurface} flex w-80 max-w-(--available-width) flex-col overflow-hidden rounded-panel p-4 [--pad:16px] [--radius-outer:var(--eased-radius-panel)] ${className}`} > {children} </FloatingLayer> );}/** The popover's heading; labels the dialog for assistive tech. */export function PopoverTitle({ className = "", children }: { className?: string; children: ReactNode }) { return <BasePopover.Title className={`text-ui font-medium text-balance text-text ${className}`}>{children}</BasePopover.Title>;}/** One line of supporting text under the title; describes the dialog for assistive tech. */export function PopoverDescription({ className = "", children }: { className?: string; children: ReactNode }) { return ( <BasePopover.Description className={`mt-1 text-ui-sm text-pretty text-text-secondary ${className}`}>{children}</BasePopover.Description> );}/** * A full-bleed action bar on a sunken strip at the bottom of the panel. It keeps the body's * `--pad` as its horizontal inset, so its first and last items sit on the content lines above * (R105): give a leading ghost button `edge="start"`, and use `rounded-control-sm` buttons. */export function PopoverFooter({ className = "", children }: { className?: string; children: ReactNode }) { return ( <div className={`-mx-(--pad) mt-(--pad) -mb-(--pad) flex items-center justify-between gap-2 border-t border-line-subtle bg-surface-sunken px-(--pad) py-3 ${className}`} > {children} </div> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Button } from "@/components/eased/button/button";import { Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverFooter, PopoverTitle, PopoverTrigger,} from "@/components/eased/popover/popover";export function SharePopover() { return ( <Popover> <PopoverTrigger>Share</PopoverTrigger> <PopoverContent align="end"> <PopoverTitle>Share “Q3 launch plan”</PopoverTitle> <PopoverDescription>People you invite can view and comment.</PopoverDescription> {/* an email field and the people with access */} <PopoverFooter> <span className="text-ui-sm text-text-muted">Anyone with the link can view</span> <PopoverClose render={<Button variant="primary" size="sm" className="radius-nested" />}>Done</PopoverClose> </PopoverFooter> </PopoverContent> </Popover> );}Examples
Icon trigger, opening to the side
Use size="icon-sm" for a square trigger and give it an aria-label. The panel flips to the other side when there is no room, and enters from the side it lands on.
<Popover> <PopoverTrigger size="icon-sm" variant="ghost" aria-label="Set reminder"> <BellIcon /> </PopoverTrigger> <PopoverContent side="right" align="start" className="w-64"> <PopoverTitle>Remind me</PopoverTitle> … </PopoverContent></Popover>Controlled
Control the open state to close the panel after an action completes.
const [open, setOpen] = useState(false);<Popover open={open} onOpenChange={setOpen}> <PopoverTrigger>Rename</PopoverTrigger> <PopoverContent> <form onSubmit={(e) => { e.preventDefault(); rename(); setOpen(false); }}>…</form> </PopoverContent></Popover>API reference
Popover
Base UI's Popover.Root, unchanged: open, defaultOpen, onOpenChange, modal (false by default; true or "trap-focus" to keep focus inside), actionsRef.
PopoverTrigger
An Eased Button that opens the popover, stays pressed (aria-expanded) while it is open, and never scales on press.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | ButtonVariant | "secondary" | The Button variant. |
size | ButtonSize | "sm" | The Button size; "icon-sm" for a square icon trigger. |
render | ReactElement | Bring your own trigger; style it with floatingTrigger from the floating primitive. | |
openOnHover | boolean | false | Also open on hover. |
delay / closeDelay | number | 300 / 0 | Hover delays in ms, with openOnHover. |
className | string | "" | Passed to the Button. |
Other Base UI Popover.Trigger props pass through.
PopoverContent
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "bottom" | Preferred side; flips on collision and the enter direction follows. |
align | "start" | "center" | "end" | "center" | |
sideOffset | number | 6 | Gap to the trigger, px. |
alignOffset | number | 0 | |
motion | Partial<FloatingMotion> | Override the enter distance, scale, fade or exit. | |
initialFocus | Base UI initialFocus | first tabbable element | Where focus goes on open. |
finalFocus | Base UI finalFocus | the trigger | Where focus returns on close. |
container | HTMLElement | null | document.body | Portal target. |
zIndex | number | 50 | Raise it inside a higher layer, such as a dialog. |
className | string | "" | Appended to the panel's classes. Set a width here; the default is w-80, never wider than the viewport. |
The panel keeps 8px from the viewport edge, and has 16px padding and corners.
PopoverTitle, PopoverDescription, PopoverFooter and PopoverClose
PopoverTitle and PopoverDescription label and describe the panel. PopoverFooter is a full-bleed sunken action bar at the bottom; it keeps the body's padding as its inset, so buttons using radius-nested get concentric corners. PopoverClose is Base UI's Popover.Close; pass render to make any button close the panel.
Keyboard
| Key | Action |
|---|---|
Enter / Space | On the trigger, opens or closes the popover. |
Esc | Closes the popover and returns focus to the trigger. |
Tab | Moves through the controls inside the panel. |
Accessibility
- Base UI gives the panel
role="dialog", labelled byPopoverTitleand described byPopoverDescription, and setsaria-expandedon the trigger. - On open, focus moves to the first tabbable element inside, or to the panel itself when opened by touch so the on-screen keyboard does not pop up. On close it returns to the trigger.
- The popover is non-modal: the rest of the page stays usable and focus is not trapped. Set
modalonPopoverwhen it should be. - An outside click or
Escdismisses it.
Motion
The panel grows out of its trigger: it scales from 0.97 at Base UI's transform origin and travels 5px toward its resting place from the side of the trigger, on the snappy spring, while its opacity fades in over 200ms. It closes in 150ms, travelling half as far and scaling half as much, with no overshoot. Both are CSS transitions, so closing during the open turns around mid-flight. The trigger presses by colour, never by scale, so the origin stays put. Reduced motion keeps only a 100ms fade.
Notes for AI
Use Popover for a small interactive panel tied to a button: give it a PopoverTitle, put actions in PopoverFooter, and set a width with className on PopoverContent when 320px is wrong. Raise zIndex when it opens inside a dialog.
Do not use it for plain hover labels (that is Tooltip) or for menus of actions (that is Dropdown Menu). Do not add your own open animation, focus management or outside-click handling, and do not scale the trigger on press: Base UI and the floating layer already handle them.
Related components
- Animated Tooltip: a short, non-interactive label on hover and focus.
- Animated Dropdown Menu: a list of actions from a button.
- Animated Modal Dialog: a modal decision or form that blocks the page.