Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Message
- Message Scroller
- Native Select
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
AI Elements
Get Started
@shadcn/react
@shadcn/helpers
Utilities
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Popover, PopoverTrigger } from "@/components/ui/popover"
export function PopoverDemo() {
return (
<PopoverTrigger>
<Button variant="outline">Open popover</Button>
<Popover className="w-80">
<div className="grid gap-4">
<div className="space-y-2">
<h4 className="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">
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="width">Width</Label>
<Input
id="width"
defaultValue="100%"
className="col-span-2 h-8"
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="maxWidth">Max. width</Label>
<Input
id="maxWidth"
defaultValue="300px"
className="col-span-2 h-8"
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="height">Height</Label>
<Input
id="height"
defaultValue="25px"
className="col-span-2 h-8"
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="maxHeight">Max. height</Label>
<Input
id="maxHeight"
defaultValue="none"
className="col-span-2 h-8"
/>
</div>
</div>
</div>
</Popover>
</PopoverTrigger>
)
}
Installation#
pnpm dlx shadcn@latest add popover
Install the following dependencies:
pnpm add react-aria-components
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { cn } from "cn"
import {
DialogTrigger,
Heading,
Popover as PopoverPrimitive,
type DialogTriggerProps,
type PopoverProps as PopoverPrimitiveProps,
} from "react-aria-components"
function PopoverTrigger({ children, ...props }: DialogTriggerProps) {
return (
<DialogTrigger data-slot="popover-trigger" {...props}>
{children}
</DialogTrigger>
)
}
function Popover({
className,
placement = "bottom",
offset = 4,
crossOffset = 0,
...props
}: Omit<PopoverPrimitiveProps, "className"> & {
className?: string
}) {
return (
<PopoverPrimitive
data-slot="popover-content"
placement={placement}
offset={offset}
crossOffset={crossOffset}
className={cn(
"z-50 flex w-72 origin-(--trigger-anchor-point) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-entering:animate-in data-entering:fade-in-0 data-entering:zoom-in-95 data-exiting:animate-out data-exiting:fade-out-0 data-exiting:zoom-out-95 data-[placement=bottom]:slide-in-from-top-2 data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
)
}
function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="popover-header"
className={cn("flex flex-col gap-0.5 text-sm", className)}
{...props}
/>
)
}
function PopoverTitle({
className,
...props
}: React.ComponentProps<typeof Heading>) {
return (
<Heading
data-slot="popover-title"
className={cn("font-medium", className)}
{...props}
/>
)
}
function PopoverDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="popover-description"
className={cn("text-muted-foreground", className)}
{...props}
/>
)
}
export {
Popover,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
}
Update the import paths to match your project setup.
Usage#
import {
Popover,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"<PopoverTrigger>
<Button variant="outline">Open Popover</Button>
<Popover>
<PopoverHeader>
<PopoverTitle>Title</PopoverTitle>
<PopoverDescription>Description text here.</PopoverDescription>
</PopoverHeader>
</Popover>
</PopoverTrigger>Composition#
Use the following composition to build a Popover:
PopoverTrigger
├── Button
└── PopoverBasic#
A simple popover with a header, title, and description.
import { Button } from "@/components/ui/button"
import {
Popover,import { Button } from "@/components/ui/button"
import {
Popover,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
export function PopoverBasic() {
return (
<PopoverTrigger>
<Button variant="outline">Open Popover</Button>
<Popover placement="bottom start">
<PopoverHeader>
<PopoverTitle>Dimensions</PopoverTitle>
<PopoverDescription>
Set the dimensions for the layer.
</PopoverDescription>
</PopoverHeader>
</Popover>
</PopoverTrigger>
)
}
Align#
Use the placement prop on Popover to control the horizontal alignment.
import { Button } from "@/components/ui/button"
import { Popover, PopoverTrigger } from "@/components/ui/popover"
import { Button } from "@/components/ui/button"
import { Popover, PopoverTrigger } from "@/components/ui/popover"
export function PopoverAlignments() {
return (
<>
<div className="flex gap-6">
<PopoverTrigger>
<Button variant="outline" size="sm">
Start
</Button>
<Popover placement="bottom start" className="w-40">
Aligned to start
</Popover>
</PopoverTrigger>
<PopoverTrigger>
<Button variant="outline" size="sm">
Center
</Button>
<Popover placement="bottom" className="w-40">
Aligned to center
</Popover>
</PopoverTrigger>
<PopoverTrigger>
<Button variant="outline" size="sm">
End
</Button>
<Popover placement="bottom end" className="w-40">
Aligned to end
</Popover>
</PopoverTrigger>
</div>
</>
)
}
With Form#
A popover with form fields inside.
import { Button } from "@/components/ui/button"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"import { Button } from "@/components/ui/button"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Popover,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
export function PopoverForm() {
return (
<>
<PopoverTrigger>
<Button variant="outline">Open Popover</Button>
<Popover className="w-64" placement="bottom start">
<PopoverHeader>
<PopoverTitle>Dimensions</PopoverTitle>
<PopoverDescription>
Set the dimensions for the layer.
</PopoverDescription>
</PopoverHeader>
<FieldGroup className="gap-4">
<Field orientation="horizontal">
<FieldLabel htmlFor="width" className="w-1/2">
Width
</FieldLabel>
<Input id="width" defaultValue="100%" />
</Field>
<Field orientation="horizontal">
<FieldLabel htmlFor="height" className="w-1/2">
Height
</FieldLabel>
<Input id="height" defaultValue="25px" />
</Field>
</FieldGroup>
</Popover>
</PopoverTrigger>
</>
)
}
RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import {// You will notice this example uses dir and data-lang attributes. // This is because this site is not RTL by default. // In your application, you won't need these.// See the RTL guide for more information.
"use client"
import {
useTranslation,
type Translations,
} from "@/components/language-selector"
import { Button } from "@/components/ui/button"
import {
Popover,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
const translations: Translations = {
en: {
dir: "ltr",
values: {
title: "Dimensions",
description: "Set the dimensions for the layer.",
start: "Start",
left: "Left",
top: "Top",
bottom: "Bottom",
right: "Right",
end: "End",
},
},
ar: {
dir: "rtl",
values: {
title: "الأبعاد",
description: "تعيين الأبعاد للطبقة.",
start: "بداية السطر",
left: "يسار",
top: "أعلى",
bottom: "أسفل",
right: "يمين",
end: "نهاية السطر",
},
},
he: {
dir: "rtl",
values: {
title: "מימדים",
description: "הגדר את המימדים לשכבה.",
start: "תחילת השורה",
left: "שמאל",
top: "למעלה",
bottom: "למטה",
right: "ימין",
end: "סוף השורה",
},
},
}
const physicalSides = ["left", "top", "bottom", "right"] as const
const logicalPlacements = ["start", "end"] as const
export function PopoverRtl() {
const { dir, t } = useTranslation(translations, "ar")
return (
<div className="grid gap-4">
<div className="flex flex-wrap justify-center gap-2">
{physicalSides.map((side) => (
<PopoverTrigger key={side}>
<Button variant="outline">{t[side]}</Button>
<Popover placement={side} dir={dir}>
<PopoverHeader>
<PopoverTitle>{t.title}</PopoverTitle>
<PopoverDescription>{t.description}</PopoverDescription>
</PopoverHeader>
</Popover>
</PopoverTrigger>
))}
</div>
<div className="flex flex-wrap justify-center gap-2">
{logicalPlacements.map((placement) => (
<PopoverTrigger key={placement}>
<Button variant="outline">{t[placement]}</Button>
<Popover placement={placement} dir={dir}>
<PopoverHeader>
<PopoverTitle>{t.title}</PopoverTitle>
<PopoverDescription>{t.description}</PopoverDescription>
</PopoverHeader>
</Popover>
</PopoverTrigger>
))}
</div>
</div>
)
}
API Reference#
See the React Aria Popover documentation.
Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel