Popover
The shadcn/ui Popover that grows out of its trigger with a short, calm animation and a neutral shadow — plus two animated React popover blocks built with Motion and Radix: a spring popover that scales from the trigger's origin, and a feedback button that morphs into a form.
- Drop-in shadcn API
- Radix positioning
- Motion blocks
- prefers-reduced-motion
"use client";
import { FeedbackPopover } from "@/components/dusk/popover/feedback-popover";
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export default function FeedbackPopoverDemo() {
return (
// Reserve room below the button: the panel opens in place, not in a portal.
<div className="flex h-64 w-80 items-start justify-start">
<FeedbackPopover
maxLength={280}
onSubmit={async (message) => {
await wait(1100);
if (message.toLowerCase().includes("error")) {
throw new Error("Couldn't send. Check your connection.");
}
}}
/>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/popover.json1. Install the dependencies.
npm install @radix-ui/react-popover2. Copy the source into
components/ui/popover.tsx.popover.tsx "use client" import * as React from "react" import * as PopoverPrimitive from "@radix-ui/react-popover" import { cn } from "@/lib/utils" /** * DuskUI Popover — a drop-in upgrade of the shadcn/ui Popover. * * Same parts, props and data-slot attributes as shadcn, plus: * - Grows out of its trigger: the scale origin follows Radix's transform * origin and it shifts in slightly from the side it opens on (150ms * ease-out), then closes quicker than it opened. * - A neutral shadow on the surface. * - Never taller than the space available; long content scrolls. * - `PopoverClose` for close buttons inside the content. * - Under `prefers-reduced-motion` it only fades. * CSS only (tw-animate-css). Radix handles focus, Escape, outside clicks, * collision avoidance and aria. */ function Popover({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Root>) { return <PopoverPrimitive.Root data-slot="popover" {...props} /> } /** The element that toggles the popover. Use `asChild` to render your own Button. */ function PopoverTrigger({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Trigger>) { return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} /> } /** The floating panel. Portalled and positioned next to the trigger (or anchor). */ function PopoverContent({ className, align = "center", sideOffset = 6, ...props }: React.ComponentProps<typeof PopoverPrimitive.Content>) { return ( <PopoverPrimitive.Portal> <PopoverPrimitive.Content data-slot="popover-content" align={align} sideOffset={sideOffset} className={cn( "z-50 max-h-(--radix-popover-content-available-height) w-72 overflow-y-auto rounded-xl border bg-popover p-4 text-popover-foreground outline-hidden", "origin-(--radix-popover-content-transform-origin)", "shadow-md ease-out", "data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:duration-150", "data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:duration-100", "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", "motion-reduce:data-[state=open]:zoom-in-100 motion-reduce:data-[state=closed]:zoom-out-100", "motion-reduce:data-[side=bottom]:slide-in-from-top-0 motion-reduce:data-[side=left]:slide-in-from-right-0 motion-reduce:data-[side=right]:slide-in-from-left-0 motion-reduce:data-[side=top]:slide-in-from-bottom-0", className )} {...props} /> </PopoverPrimitive.Portal> ) } /** Positions the popover against something other than the trigger. */ function PopoverAnchor({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Anchor>) { return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} /> } /** Closes the popover. Use `asChild` to render your own Button. */ function PopoverClose({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Close>) { return <PopoverPrimitive.Close data-slot="popover-close" {...props} /> } export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor, PopoverClose }
Replaces components/ui/popover.tsx with the same exports and props, plus PopoverClose. Animations are CSS (tw-animate-css), so the base needs no Motion.
Usage
import { Button } from "@/components/ui/button"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
export function LayerSettings() {
return (
<Popover>
<PopoverTrigger asChild>
<Button variant="outline">Dimensions</Button>
</PopoverTrigger>
<PopoverContent>{/* form */}</PopoverContent>
</Popover>
)
}Examples
Default
Scales out of the trigger with a short ease-out and closes quicker than it opened. Focus moves into the popover; Escape or a click outside closes it and focus returns to the trigger.
import { Settings2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
const fields = [
{ id: "width", label: "Width", value: "100%" },
{ id: "max-width", label: "Max width", value: "640px" },
{ id: "height", label: "Height", value: "auto" },
];
export default function PopoverBasicDemo() {
return (
<Popover>
<PopoverTrigger asChild>
<Button variant="outline">
<Settings2 />
Dimensions
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<div className="grid gap-4">
<div className="space-y-1">
<h4 className="text-sm leading-none font-medium">Dimensions</h4>
<p className="text-sm text-muted-foreground">Set the dimensions for the layer.</p>
</div>
<div className="grid gap-2">
{fields.map((field) => (
<div key={field.id} className="grid grid-cols-3 items-center gap-4">
<label htmlFor={`popover-${field.id}`} className="text-sm">
{field.label}
</label>
<Input id={`popover-${field.id}`} defaultValue={field.value} className="col-span-2 h-8" />
</div>
))}
</div>
</div>
</PopoverContent>
</Popover>
);
}Sides
The scale origin comes from --radix-popover-content-transform-origin, so the popover always grows from the edge facing its trigger — including after Radix flips it to stay on screen.
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
const sides = ["top", "right", "bottom", "left"] as const;
export default function PopoverSidesDemo() {
return (
<>
{sides.map((side) => (
<Popover key={side}>
<PopoverTrigger asChild>
<Button variant="outline" size="sm" className="capitalize">
{side}
</Button>
</PopoverTrigger>
<PopoverContent side={side} className="w-48 text-sm">
Grows out of the trigger from the <span className="font-medium text-foreground">{side}</span>.
</PopoverContent>
</Popover>
))}
</>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
Animated Popover
A Motion-powered popover that scales out of its trigger's transform origin, then fades its content in a beat later; the exit is short and crisp. Optional showArrow draws an arrow that follows Radix's placement.
"use client";
import * as React from "react";
import { Check, Copy, Link2, Share2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
AnimatedPopover,
AnimatedPopoverContent,
AnimatedPopoverTrigger,
} from "@/components/dusk/popover/animated-popover";
const link = "https://duskui.com/s/aurora";
export default function AnimatedPopoverDemo() {
const [copied, setCopied] = React.useState(false);
React.useEffect(() => {
if (!copied) return;
const timer = window.setTimeout(() => setCopied(false), 1500);
return () => window.clearTimeout(timer);
}, [copied]);
return (
<AnimatedPopover>
<AnimatedPopoverTrigger asChild>
<Button>
<Share2 />
Share
</Button>
</AnimatedPopoverTrigger>
<AnimatedPopoverContent showArrow className="w-80">
<div className="flex items-start gap-3">
<span className="grid size-9 shrink-0 place-items-center rounded-md border bg-muted text-muted-foreground">
<Link2 className="size-4" aria-hidden />
</span>
<div>
<h4 className="text-sm font-medium">Share this project</h4>
<p className="text-sm text-muted-foreground">Anyone with the link can view.</p>
</div>
</div>
<div className="mt-4 flex gap-2">
<Input readOnly value={link} aria-label="Share link" className="h-8 font-mono text-xs" />
<Button
size="icon-sm"
variant="outline"
aria-label={copied ? "Copied" : "Copy link"}
onClick={() => {
void navigator.clipboard?.writeText(link);
setCopied(true);
}}
>
{copied ? <Check className="text-primary" /> : <Copy />}
</Button>
</div>
</AnimatedPopoverContent>
</AnimatedPopover>
);
}$ npx shadcn@latest add https://duskui.com/r/animated-popover.json1. Install the dependencies.
npm install motion @radix-ui/react-popover2. Copy the source into
components/dusk/popover/animated-popover.tsx.animated-popover.tsx "use client"; import * as React from "react"; import * as PopoverPrimitive from "@radix-ui/react-popover"; import { AnimatePresence, motion, useReducedMotion, type Variants } from "motion/react"; import { PopoverAnchor, PopoverClose, PopoverTrigger } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; type AnimatedPopoverContextValue = { open: boolean; reduceMotion: boolean }; const AnimatedPopoverContext = React.createContext<AnimatedPopoverContextValue | null>(null); function useAnimatedPopover() { const context = React.useContext(AnimatedPopoverContext); if (!context) throw new Error("AnimatedPopover parts must be used inside <AnimatedPopover>."); return context; } export interface AnimatedPopoverProps extends Omit<React.ComponentProps<typeof PopoverPrimitive.Root>, "open" | "defaultOpen" | "onOpenChange"> { open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; } /** * A popover that scales out of its trigger. The scale origin comes from * Radix's `--radix-popover-content-transform-origin`, so it always grows from * the edge nearest the trigger, even after flipping to avoid the viewport * edge; the content then fades in a beat later and the exit is quick. Radix * handles focus, Escape, outside clicks and aria. Fades only under reduced motion. */ export function AnimatedPopover({ open: openProp, defaultOpen = false, onOpenChange, ...props }: AnimatedPopoverProps) { const reduceMotion = useReducedMotion() ?? false; const [internalOpen, setInternalOpen] = React.useState(defaultOpen); const open = openProp ?? internalOpen; const setOpen = React.useCallback( (next: boolean) => { if (openProp === undefined) setInternalOpen(next); onOpenChange?.(next); }, [openProp, onOpenChange] ); const value = React.useMemo(() => ({ open, reduceMotion }), [open, reduceMotion]); return ( <AnimatedPopoverContext.Provider value={value}> <PopoverPrimitive.Root open={open} onOpenChange={setOpen} {...props} /> </AnimatedPopoverContext.Provider> ); } /** The element that toggles the popover. Use `asChild` to render your own Button. */ export const AnimatedPopoverTrigger = PopoverTrigger; /** Positions the popover against something other than the trigger. */ export const AnimatedPopoverAnchor = PopoverAnchor; /** Closes the popover. Use `asChild` to render your own Button. */ export const AnimatedPopoverClose = PopoverClose; export interface AnimatedPopoverContentProps extends Omit<React.ComponentProps<typeof PopoverPrimitive.Content>, "forceMount" | "asChild" | "children"> { children?: React.ReactNode; /** Draw a small arrow pointing at the trigger. */ showArrow?: boolean; } /** The floating panel. Portalled, positioned by Radix and animated by Motion. */ export function AnimatedPopoverContent({ className, children, align = "center", sideOffset = 8, showArrow = false, ...props }: AnimatedPopoverContentProps) { const { open, reduceMotion } = useAnimatedPopover(); const surface: Variants = reduceMotion ? { closed: { opacity: 0, transition: { duration: 0.1 } }, open: { opacity: 1, transition: { duration: 0.15 } } } : { closed: { opacity: 0, scale: 0.96, transition: { duration: 0.12, ease: "easeIn" } }, open: { opacity: 1, scale: 1, transition: { type: "spring", duration: 0.25, bounce: 0.1 }, }, }; const inner: Variants = reduceMotion ? { closed: { opacity: 1 }, open: { opacity: 1 } } : { closed: { opacity: 0, transition: { duration: 0.08 } }, open: { opacity: 1, transition: { duration: 0.2, ease: "easeOut", delay: 0.05 } }, }; return ( <AnimatePresence> {open && ( // forceMount hands mounting to AnimatePresence so the exit animation can play. <PopoverPrimitive.Portal key="popover" forceMount> <PopoverPrimitive.Content forceMount asChild align={align} sideOffset={sideOffset} {...props}> <motion.div className={cn( "z-50 w-72 rounded-xl border bg-popover p-4 text-popover-foreground outline-none", "origin-(--radix-popover-content-transform-origin)", "shadow-md", className )} variants={surface} initial="closed" animate="open" exit="closed" > <motion.div variants={inner}>{children}</motion.div> {showArrow && ( <PopoverPrimitive.Arrow asChild width={14} height={7}> {/* Nudged 1px into the surface so its base covers the border line. */} <svg viewBox="0 0 14 7" className="block -translate-y-px fill-popover stroke-border" aria-hidden> <path d="M0 0 L7 6.5 L14 0" strokeWidth={1} /> </svg> </PopoverPrimitive.Arrow> )} </motion.div> </PopoverPrimitive.Content> </PopoverPrimitive.Portal> )} </AnimatePresence> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| open / defaultOpen / onOpenChange | boolean / boolean / (open: boolean) => void | — | Open state (on AnimatedPopover). |
| AnimatedPopoverTrigger / Anchor / Close | Radix props | — | Use asChild to render your own elements. |
| AnimatedPopoverContent | Radix Content props & { showArrow?: boolean } | — | side, align (default center), sideOffset (default 8)… |
Feedback Popover
A pill button that morphs into a feedback form: the surface, icon and label share Motion layoutIds, so the pill stretches into the panel and the label flies into the title. Return a promise from onSubmit for a loading state; throw to show an error inline (type “error” in the demo). On success it shows a check, then shrinks back into the button. It renders inline rather than in a portal so the morph can be measured, so leave room around it.
"use client";
import { FeedbackPopover } from "@/components/dusk/popover/feedback-popover";
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export default function FeedbackPopoverDemo() {
return (
// Reserve room below the button: the panel opens in place, not in a portal.
<div className="flex h-64 w-80 items-start justify-start">
<FeedbackPopover
maxLength={280}
onSubmit={async (message) => {
await wait(1100);
if (message.toLowerCase().includes("error")) {
throw new Error("Couldn't send. Check your connection.");
}
}}
/>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/feedback-popover.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/popover/feedback-popover.tsx.feedback-popover.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion, type Transition } from "motion/react"; import { CheckIcon, MessageSquareText } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; const morph: Transition = { type: "spring", bounce: 0.1, duration: 0.35 }; const fade: Transition = { duration: 0.2, ease: "easeOut" }; type Status = "idle" | "submitting" | "success" | "error"; export interface FeedbackPopoverProps { /** Text on the trigger button, which becomes the panel title. */ label?: string; /** Icon on the trigger. Pass null to hide it. */ icon?: React.ReactNode; placeholder?: string; /** Runs on submit. Return a promise to show the loading state; throw to show an error. */ onSubmit?: (message: string) => unknown | Promise<unknown>; /** Shown after a successful submit, before the panel closes itself. */ successMessage?: React.ReactNode; /** How long the success state stays before closing, in ms. */ successDuration?: number; /** Maximum message length. Shows a counter when set. */ maxLength?: number; /** Open downward from the button (bottom) or upward (top). */ side?: "top" | "bottom"; /** Line the panel up with the button's left (start) or right (end) edge. */ align?: "start" | "end"; open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; className?: string; /** Classes for the open panel (e.g. a different width). */ panelClassName?: string; } /** * A feedback button that morphs into a small form. The button and the panel * share a Motion `layoutId`, so the pill stretches into the panel and the * label flies into the title; on submit the form crossfades to a success * state and the panel shrinks back into the button. Non-modal like a popover: * focus moves to the textarea, Escape or a click outside closes it and focus * returns to the button. ⌘/Ctrl + Enter submits. Renders inline (not * portalled) so the morph can be measured: leave room around it and avoid * `overflow: hidden` ancestors. Fades instead of morphing under reduced motion. */ export function FeedbackPopover({ label = "Feedback", icon = <MessageSquareText />, placeholder = "What's on your mind?", onSubmit, successMessage = "Thanks! We read every message.", successDuration = 1600, maxLength, side = "bottom", align = "start", open: openProp, defaultOpen = false, onOpenChange, className, panelClassName, }: FeedbackPopoverProps) { const id = React.useId(); const reduceMotion = useReducedMotion() ?? false; const rootRef = React.useRef<HTMLDivElement>(null); const triggerRef = React.useRef<HTMLButtonElement>(null); const textareaRef = React.useRef<HTMLTextAreaElement>(null); const [internalOpen, setInternalOpen] = React.useState(defaultOpen); const open = openProp ?? internalOpen; const [message, setMessage] = React.useState(""); const [status, setStatus] = React.useState<Status>("idle"); const [error, setError] = React.useState<string | null>(null); const layoutId = (part: string) => (reduceMotion ? undefined : `${id}-${part}`); const panelId = `${id}-panel`; const titleId = `${id}-title`; const errorId = `${id}-error`; const setOpen = React.useCallback( (next: boolean, { restoreFocus = true } = {}) => { if (openProp === undefined) setInternalOpen(next); onOpenChange?.(next); if (!next) { setStatus("idle"); setError(null); if (restoreFocus) triggerRef.current?.focus({ preventScroll: true }); } }, [openProp, onOpenChange] ); // Focus the textarea once the panel is mounted. React.useEffect(() => { if (open) textareaRef.current?.focus({ preventScroll: true }); }, [open]); // Close on a pointer press outside the component (like a popover). React.useEffect(() => { if (!open) return; const onPointerDown = (event: PointerEvent) => { if (!rootRef.current?.contains(event.target as Node)) setOpen(false, { restoreFocus: false }); }; document.addEventListener("pointerdown", onPointerDown); return () => document.removeEventListener("pointerdown", onPointerDown); }, [open, setOpen]); // After a successful submit, show the thank-you state for a moment, then close. React.useEffect(() => { if (status !== "success") return; const timer = window.setTimeout(() => { setMessage(""); setOpen(false); }, successDuration); return () => window.clearTimeout(timer); }, [status, successDuration, setOpen]); const submit = async () => { if (!message.trim() || status === "submitting" || status === "success") return; setStatus("submitting"); setError(null); try { await onSubmit?.(message.trim()); setStatus("success"); } catch (err) { setStatus("error"); setError(err instanceof Error ? err.message : "Something went wrong. Try again."); } }; const busy = status === "submitting"; const done = status === "success"; return ( <div ref={rootRef} className={cn("relative inline-block", className)}> <motion.button ref={triggerRef} type="button" layoutId={layoutId("surface")} transition={morph} aria-expanded={open} aria-haspopup="dialog" aria-controls={open ? panelId : undefined} // Hidden under the open panel, so keep it out of the tab order meanwhile. tabIndex={open ? -1 : undefined} onClick={() => setOpen(!open)} style={{ borderRadius: 999 }} className={cn( "inline-flex h-9 items-center gap-2 border bg-card px-4 text-sm font-medium text-card-foreground outline-none", "transition-[border-color,box-shadow,background-color] duration-150 hover:bg-accent", "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40", "[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground" )} > {icon && ( <motion.span layoutId={layoutId("icon")} transition={morph} className="inline-flex"> {icon} </motion.span> )} <motion.span layoutId={layoutId("label")} layout="position" transition={morph}> {label} </motion.span> </motion.button> <AnimatePresence> {open && ( <motion.div key="panel" id={panelId} role="dialog" aria-labelledby={titleId} layoutId={layoutId("surface")} transition={morph} initial={reduceMotion ? { opacity: 0 } : undefined} animate={reduceMotion ? { opacity: 1 } : undefined} exit={reduceMotion ? { opacity: 0 } : undefined} style={{ borderRadius: 12 }} onKeyDown={(event) => { if (event.key === "Escape") { event.stopPropagation(); setOpen(false); } }} onBlur={(event) => { const next = event.relatedTarget as Node | null; if (next && (!rootRef.current?.contains(next) || next === triggerRef.current)) { setOpen(false, { restoreFocus: false }); } }} className={cn( "absolute z-50 w-80 overflow-hidden border bg-popover text-popover-foreground", "shadow-lg", side === "bottom" ? "top-0" : "bottom-0", align === "start" ? "left-0" : "right-0", panelClassName )} > <div className="flex items-center gap-2 px-4 pt-3.5 pb-2 text-sm font-medium [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground"> {icon && ( <motion.span layoutId={layoutId("icon")} transition={morph} className="inline-flex"> {icon} </motion.span> )} <motion.span id={titleId} layoutId={layoutId("label")} layout="position" transition={morph}> {label} </motion.span> </div> <div className="grid"> {/* The form stays mounted under the success state so the panel never changes size. */} <motion.form className="col-start-1 row-start-1 px-4 pb-4" inert={done} aria-hidden={done || undefined} initial={{ opacity: 0, y: reduceMotion ? 0 : 6 }} animate={{ opacity: done ? 0 : 1, y: 0, transition: { ...fade, delay: done || reduceMotion ? 0 : 0.12 } }} exit={{ opacity: 0, transition: { duration: 0.08 } }} onSubmit={(event) => { event.preventDefault(); void submit(); }} > <textarea ref={textareaRef} value={message} onChange={(event) => { setMessage(event.target.value); if (status === "error") setStatus("idle"); }} onKeyDown={(event) => { if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) { event.preventDefault(); void submit(); } }} placeholder={placeholder} maxLength={maxLength} rows={4} aria-label={`${label} message`} aria-invalid={status === "error" || undefined} aria-describedby={error ? errorId : undefined} className={cn( "block w-full resize-none rounded-lg border border-input bg-input/30 px-3 py-2 text-sm outline-none", "placeholder:text-muted-foreground transition-[border-color,box-shadow] duration-200", "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/30", "aria-invalid:border-destructive aria-invalid:ring-destructive/20" )} /> <div className="mt-1.5 flex min-h-5 items-center justify-between gap-2 text-xs"> <AnimatePresence initial={false} mode="wait"> {error ? ( <motion.p key="error" id={errorId} role="alert" className="truncate text-destructive" initial={{ opacity: 0, x: reduceMotion ? 0 : -4 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0 }} transition={fade} > {error} </motion.p> ) : ( <motion.p key="hint" className="text-muted-foreground" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={fade} > <kbd className="font-sans">⌘</kbd> <kbd className="font-sans">↵</kbd> to send </motion.p> )} </AnimatePresence> {maxLength && ( <span className="shrink-0 text-muted-foreground tabular-nums" aria-hidden> {message.length}/{maxLength} </span> )} </div> <div className="mt-3 flex justify-end gap-2"> <Button type="button" variant="ghost" size="sm" onClick={() => setOpen(false)}> Cancel </Button> <Button type="submit" size="sm" loading={busy} loadingText="Sending" disabled={!message.trim() && !busy} > Send </Button> </div> </motion.form> <AnimatePresence> {done && ( <motion.div key="success" role="status" className="col-start-1 row-start-1 flex flex-col items-center justify-center gap-3 px-6 pb-6 text-center" initial={{ opacity: 0, scale: reduceMotion ? 1 : 0.96 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, transition: { duration: 0.1 } }} transition={reduceMotion ? fade : { type: "spring", duration: 0.25, bounce: 0.1 }} > <span className="grid size-10 place-items-center rounded-full border text-primary"> <CheckIcon className="size-5" aria-hidden /> </span> <p className="text-sm text-muted-foreground">{successMessage}</p> </motion.div> )} </AnimatePresence> </div> </motion.div> )} </AnimatePresence> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| onSubmit | (message: string) => unknown | Promise<unknown> | — | Runs on submit. Throw to keep the panel open with an error. |
| label | string | "Feedback" | Button text and panel title. |
| icon | ReactNode | null | — | Leading icon. null hides it. |
| placeholder | string | — | Textarea placeholder. |
| successMessage | ReactNode | — | Shown after a successful submit. |
| successDuration | number | 1600 | Milliseconds to show the success state before closing. |
| maxLength | number | — | Character limit; shows a counter. |
| side / align | "top" | "bottom" / "start" | "end" | "bottom" / "start" | Open downward or upward, from the left or right edge. |
| open / defaultOpen / onOpenChange | boolean / boolean / (open: boolean) => void | — | Open state. |
| panelClassName | string | — | Classes for the open panel, e.g. a width. |
API Reference
Same parts as shadcn/ui: Popover, PopoverTrigger, PopoverContent and PopoverAnchor, plus PopoverClose. Each forwards the Radix Popover props.
| Prop | Type | Default | Description |
|---|---|---|---|
| open / onOpenChange | boolean / (open: boolean) => void | — | Controlled state (on Popover). |
| modal | boolean | false | Trap focus and block outside interaction (on Popover). |
| side / align / sideOffset | string / string / number | "bottom" / "center" / 6 | Placement (on PopoverContent). |
| onOpenAutoFocus / onEscapeKeyDown / onInteractOutside | (event) => void | — | Radix hooks on PopoverContent; call preventDefault() to override. |
Accessibility
- Built on Radix Popover: the trigger has
aria-expandedandaria-controls, the content is arole="dialog", Escape and outside clicks close it and focus returns to the trigger. - Feedback Popover follows the same pattern by hand:
aria-expanded/aria-haspopup="dialog"on the button, a labelled dialog, focus on the textarea, Escape to close, and errors and success announced viarole="alert"/role="status". - Under prefers-reduced-motion popovers only fade and the feedback button crossfades instead of morphing.