shadcn.io is not affiliated with official shadcn/ui
Shadcn Popover for React
Overlay with extra info or options on trigger.
Installation
bunx --bun shadcn@latest add https://kit.dev/r/base/popover.jsonnpx shadcn@latest add https://kit.dev/r/base/popover.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/popover.jsonyarn shadcn@latest add https://kit.dev/r/base/popover.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add @base-ui/reactnpm install @base-ui/reactpnpm add @base-ui/reactyarn add @base-ui/reactCopy and paste the following code into your project.
"use client";
import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
import type React from "react";
import { cn } from "@/lib/utils";
export const Popover = (props: PopoverPrimitive.Root.Props) => (
<PopoverPrimitive.Root data-slot="popover" {...props} />
);
export const PopoverTrigger = (props: PopoverPrimitive.Trigger.Props) => (
<PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
);
export const PopoverContent = (
props: PopoverPrimitive.Popup.Props &
Pick<
PopoverPrimitive.Positioner.Props,Update the import paths to match your project setup.
Anatomy
PopoverArrow
└── PopoverArrowTip
PopoverAnchor
PopoverTrigger
PopoverIndicator
PopoverPositioner
PopoverContent
PopoverTitle
PopoverDescription
PopoverCloseUsage
import { Button } from "@/components/ui/button";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
Popover,
PopoverContent,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover";<Popover>
<PopoverTrigger asChild>
<Button variant="outline">Open popover</Button>
</PopoverTrigger>
<PopoverContent className="w-64 max-w-full">
<PopoverHeader>
<PopoverTitle>Dimensions</PopoverTitle>
<PopoverDescription>
Set the dimensions for the layer.
</PopoverDescription>
</PopoverHeader>
<FieldGroup className="min-w-0 gap-3">
<Field className="min-w-0" orientation="horizontal">
<FieldLabel className="w-1/2">Width</FieldLabel>
<Input className="min-w-0" defaultValue="100%" />
</Field>
<Field className="min-w-0" orientation="horizontal">
<FieldLabel className="w-1/2">Height</FieldLabel>
<Input className="min-w-0" defaultValue="25px" />
</Field>
</FieldGroup>
</PopoverContent>
</Popover>Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
Demos
Basic
A simple popover with a header, title, and description.
Alignments
Use placement on the popover to control alignment.
Form
A popover with form fields inside.
Rtl
Right-to-left popover. See the RTL configuration guide for document direction.
API Reference
Popover
PropType
AttributeType
PopoverTrigger
button
PropType
AttributeType
PopoverPositioner
div
AttributeType
CSS variableType
--transform-originstringPopoverTitle
h1
PropType
AttributeType
PopoverDescription
p
PropType
AttributeType
PopoverContent
div
PropType
AttributeType
CSS variableType
--transform-originstringPopoverHeader
PropType
AttributeType