View fulldotdev/ui on GitHub

Popover

Displays rich content in a floating layer, triggered by a button.

Installation

npx shadcn@latest add @fulldev/popover

Usage

import { buttonVariants } from "@/components/ui/button"
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover"
<Popover>
  <PopoverTrigger class={buttonVariants({ variant: "outline" })}>
    Open Popover
  </PopoverTrigger>
  <PopoverContent>
    <PopoverHeader>
      <PopoverTitle>Title</PopoverTitle>
      <PopoverDescription>Description text here.</PopoverDescription>
    </PopoverHeader>
  </PopoverContent>
</Popover>

PopoverTrigger is a plain button: style it with buttonVariants, or give another button data-slot="popover-trigger" inside Popover. Add data-slot="popover-close" to a button inside the content to close it.

Composition

Popover
├── PopoverTrigger
└── PopoverContent
    └── PopoverHeader
        ├── PopoverTitle
        └── PopoverDescription

Basic

A simple popover with a header, title, and description.

Align

Use the align prop on PopoverContent to control the horizontal alignment.

With Form

A popover with form fields inside.

RTL

side takes physical sides only, so this example resolves inline-start and inline-end for the text direction.

API Reference

Source: src/components/ui/popover

Behavior comes from @data-slot/popover.

Popover

PropTypeDefault
defaultOpenbooleanfalse
portalbooleantrue
closeOnClickOutsidebooleantrue
closeOnEscapebooleantrue

The positioning props of PopoverContent also work on Popover.

PopoverContent

PropTypeDefault
side"top" | "right" | "bottom" | "left""bottom"
align"start" | "center" | "end""center"
sideOffsetnumber4
alignOffsetnumber0
avoidCollisionsbooleantrue
collisionPaddingnumber8

Events

Listen for popover:change on the Popover root, and dispatch popover:set with { open: boolean } to open or close it from a script.