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/radix/popover.jsonnpx shadcn@latest add https://kit.dev/r/radix/popover.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/popover.jsonyarn shadcn@latest add https://kit.dev/r/radix/popover.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add radix-uinpm install radix-uipnpm add radix-uiyarn add radix-uiCopy and paste the following code into your project.
"use client";
import { Popover as PopoverPrimitive } from "radix-ui";
import type React from "react";
import { cn } from "@/lib/utils";
export const Popover = (
props: React.ComponentProps<typeof PopoverPrimitive.Root>
) => <PopoverPrimitive.Root data-slot="popover" {...props} />;
export const PopoverTrigger = (
props: React.ComponentProps<typeof PopoverPrimitive.Trigger>
) => <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
export const PopoverAnchor = (
props: React.ComponentProps<typeof PopoverPrimitive.Anchor>
) => <PopoverPrimitive.Anchor data-slot="popover-anchor" {...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
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
PopoverAnchor
div
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
PopoverTrigger
button
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
PopoverContent
div
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
CSS variableType
--radix-popover-content-transform-originstringPopoverHeader
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
PopoverTitle
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType
PopoverDescription
PropType
open?booleandefaultOpen?booleanchildren?React.ReactNodemodal?booleanAttributeType