Get Started
Input
Feedback
Display
Installation
i18n
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"Installation#
pnpm dlx shadcn@latest add https://ui.tyap.me/r/styles/base/popover.jsonnpx shadcn@latest add https://ui.tyap.me/r/styles/base/popover.jsonyarn dlx shadcn@latest add https://ui.tyap.me/r/styles/base/popover.jsonbunx --bun shadcn@latest add https://ui.tyap.me/r/styles/base/popover.json
Install the following dependencies:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { Popover as PopoverPrimitive } from "@base-ui/react/popover"
import { cn } from "@/lib/utils"
function Popover({ ...props }: PopoverPrimitive.Root.Props) {
return <PopoverPrimitive.Root data-slot="popover" {...props} />
}
function PopoverTrigger({
asChild,
children,
render,
...props
}: PopoverPrimitive.Trigger.Props & {
asChild?: boolean
children?: React.ReactNode
}) {
const resolvedRender =
asChild && React.isValidElement(children) ? children : render
return (
<PopoverPrimitive.Trigger
data-slot="popover-trigger"
render={resolvedRender}
{...props}
>
{asChild ? undefined : children}
</PopoverPrimitive.Trigger>
)
}
function PopoverContent({
className,
align = "center",
alignOffset = 0,
side = "bottom",
sideOffset = 4,
...props
}: PopoverPrimitive.Popup.Props &
Pick<
PopoverPrimitive.Positioner.Props,
"align" | "alignOffset" | "side" | "sideOffset"
>) {
return (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Positioner
align={align}
alignOffset={alignOffset}
side={side}
sideOffset={sideOffset}
className="isolate z-50"
>
<PopoverPrimitive.Popup
data-slot="popover-content"
className={cn(
"z-50 w-72 origin-(--transform-origin) outline-hidden",
className
)}
{...props}
/>
</PopoverPrimitive.Positioner>
</PopoverPrimitive.Portal>
)
}
function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="popover-header"
className={cn(className)}
{...props}
/>
)
}
function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
return (
<PopoverPrimitive.Title
data-slot="popover-title"
className={cn(className)}
{...props}
/>
)
}
function PopoverDescription({
className,
...props
}: PopoverPrimitive.Description.Props) {
return (
<PopoverPrimitive.Description
data-slot="popover-description"
className={cn(className)}
{...props}
/>
)
}
export {
Popover,
PopoverContent,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
}
Update the import paths to match your project setup.
Usage#
import {
Popover,
PopoverContent,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"<Popover>
<PopoverTrigger render={<Button variant="outline" />}>
Open Popover
</PopoverTrigger>
<PopoverContent>
<PopoverHeader>
<PopoverTitle>Title</PopoverTitle>
<PopoverDescription>Description text here.</PopoverDescription>
</PopoverHeader>
</PopoverContent>
</Popover>Composition#
Use the following composition to build a Popover:
Popover
├── PopoverTrigger
└── PopoverContentExamples#
Basic#
A simple popover with a header, title, and description.
import { Button } from "@/components/ui/button"
import {
Popover,Align#
Use the align prop on PopoverContent to control the horizontal alignment.
import { Button } from "@/components/ui/button"
import {
Popover,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"RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import {API Reference#
See the Base UI Popover documentation.