# Popover

> A floating tonal surface anchored to a trigger element, supporting rich content, actions, and spring entrance motion.

Canonical URL: https://taut-ui.com/docs/components/popover

```tsx
import { Button } from "@/components/ui/button";
import {
  Popover,
  PopoverDescription,
  PopoverPopup,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover";

export default function Particle() {
  return (
    <Popover>
      <PopoverTrigger
        render={<Button variant="outline">Open Popover</Button>}
      />
      <PopoverPopup>
        <PopoverTitle>What&apos;s new</PopoverTitle>
        <PopoverDescription>
          We just shipped a major update with new components and improved
          performance across the board.
        </PopoverDescription>
      </PopoverPopup>
    </Popover>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/popover.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react class-variance-authority
```

- Copy and paste the following code into your project.

```tsx title="components/ui/popover.tsx"
"use client";

import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
import { cva, type VariantProps } from "class-variance-authority";
import type React from "react";
import { cn } from "@/lib/utils";

export const popoverPopupVariants = cva(
  [
    "text-(color:--pop-fg) relative flex max-h-(--available-height) min-w-10 max-w-80 origin-(--transform-origin) flex-col gap-1.5 overflow-y-auto rounded-3xl bg-(--pop-bg) p-4 outline-none",
    "shadow-[0_0_0_0.0625rem_var(--pop-ring),0_0.25rem_0.5rem_0.1875rem_rgb(0_0_0/0.15),0_0.0625rem_0.1875rem_0_rgb(0_0_0/0.3)]",
    "[transition-duration:350ms,150ms] [transition-property:scale,opacity] [transition-timing-function:linear(0,0.42_6%,0.86_14%,1.06_24%,1.07_32%,1.02_46%,0.995_60%,1),ease] motion-reduce:transition-none",
    "data-starting-style:scale-75 data-starting-style:opacity-0",
    "data-ending-style:scale-90 data-ending-style:opacity-0 data-ending-style:[transition-duration:100ms] data-ending-style:[transition-timing-function:ease]",
  ],
  {
    defaultVariants: { colorScheme: "standard" },
    variants: {
      colorScheme: {
        standard:
          "[--pop-bg:color-mix(in_oklab,var(--color-popover),var(--color-primary)_8%)] [--pop-fg:var(--color-popover-foreground)] [--pop-ring:color-mix(in_oklab,var(--color-popover),var(--color-primary)_22%)]",
        vibrant:
          "[--pop-bg:color-mix(in_oklab,var(--color-popover),var(--color-primary)_18%)] [--pop-fg:var(--color-secondary-foreground)] [--pop-ring:color-mix(in_oklab,var(--color-popover),var(--color-primary)_32%)]",
      },
    },
  },
);

export const PopoverCreateHandle: typeof PopoverPrimitive.createHandle =
  PopoverPrimitive.createHandle;

export const Popover: typeof PopoverPrimitive.Root = PopoverPrimitive.Root;

export const PopoverPortal: typeof PopoverPrimitive.Portal =
  PopoverPrimitive.Portal;

export function PopoverTrigger({
  className,
  children,
  ...props
}: PopoverPrimitive.Trigger.Props): React.ReactElement {
  return (
    <PopoverPrimitive.Trigger
      className={className}
      data-slot="popover-trigger"
      {...props}
    >
      {children}
    </PopoverPrimitive.Trigger>
  );
}

export type PopoverPopupProps = PopoverPrimitive.Popup.Props &
  VariantProps<typeof popoverPopupVariants> & {
    portalProps?: PopoverPrimitive.Portal.Props;
    side?: PopoverPrimitive.Positioner.Props["side"];
    align?: PopoverPrimitive.Positioner.Props["align"];
    sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"];
    alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"];
    anchor?: PopoverPrimitive.Positioner.Props["anchor"];
  };

export function PopoverPopup({
  children,
  className,
  side = "bottom",
  align = "center",
  sideOffset = 8,
  alignOffset = 0,
  anchor,
  portalProps,
  colorScheme,
  ...props
}: PopoverPopupProps): React.ReactElement {
  return (
    <PopoverPortal {...portalProps}>
      <PopoverPrimitive.Positioner
        align={align}
        alignOffset={alignOffset}
        anchor={anchor}
        className="z-50 max-w-(--available-width) [transition-duration:350ms] [transition-property:top,left,right,bottom,transform] [transition-timing-function:linear(0,0.42_6%,0.86_14%,1.06_24%,1.07_32%,1.02_46%,0.995_60%,1)] data-instant:transition-none motion-reduce:transition-none"
        data-slot="popover-positioner"
        side={side}
        sideOffset={sideOffset}
      >
        <PopoverPrimitive.Popup
          className={cn(popoverPopupVariants({ colorScheme }), className)}
          data-slot="popover-popup"
          {...props}
        >
          {children}
        </PopoverPrimitive.Popup>
      </PopoverPrimitive.Positioner>
    </PopoverPortal>
  );
}

export function PopoverClose({
  ...props
}: PopoverPrimitive.Close.Props): React.ReactElement {
  return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
}

export function PopoverTitle({
  className,
  ...props
}: PopoverPrimitive.Title.Props): React.ReactElement {
  return (
    <PopoverPrimitive.Title
      className={cn(
        "font-heading font-semibold text-base leading-6 tracking-tight",
        className,
      )}
      data-slot="popover-title"
      {...props}
    />
  );
}

export function PopoverDescription({
  className,
  ...props
}: PopoverPrimitive.Description.Props): React.ReactElement {
  return (
    <PopoverPrimitive.Description
      className={cn("text-muted-foreground text-sm leading-5", className)}
      data-slot="popover-description"
      {...props}
    />
  );
}

export function PopoverActions({
  className,
  ...props
}: React.ComponentProps<"div">): React.ReactElement {
  return (
    <div
      className={cn(
        "-me-1 mt-2 -mb-1 flex flex-wrap items-center justify-end gap-2",
        className,
      )}
      data-slot="popover-actions"
      {...props}
    />
  );
}

export { PopoverPrimitive, PopoverPopup as PopoverContent };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import { Button } from "@/components/ui/button"
import {
  Popover,
  PopoverActions,
  PopoverClose,
  PopoverDescription,
  PopoverPopup,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover"
```

```tsx
<Popover>
  <PopoverTrigger render={<Button variant="outline">Open Popover</Button>} />
  <PopoverPopup>
    <PopoverTitle>Popover Title</PopoverTitle>
    <PopoverDescription>
      Supporting copy displayed inside the popover surface.
    </PopoverDescription>
    <PopoverActions>
      <PopoverClose render={<Button size="xs" />}>Done</PopoverClose>
    </PopoverActions>
  </PopoverPopup>
</Popover>
```

## Examples [#examples]

### With Actions [#with-actions]

```tsx
import { Button } from "@/components/ui/button";
import {
  Popover,
  PopoverActions,
  PopoverClose,
  PopoverDescription,
  PopoverPopup,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover";

export default function Particle() {
  return (
    <Popover>
      <PopoverTrigger render={<Button variant="outline">Updates</Button>} />
      <PopoverPopup>
        <PopoverTitle>Sync completed</PopoverTitle>
        <PopoverDescription>
          All workspace tokens and registry files are up to date with the latest
          release.
        </PopoverDescription>
        <PopoverActions>
          <PopoverClose render={<Button size="xs" variant="ghost" />}>
            Dismiss
          </PopoverClose>
          <PopoverClose render={<Button size="xs" />}>Got it</PopoverClose>
        </PopoverActions>
      </PopoverPopup>
    </Popover>
  );
}
```

### Vibrant [#vibrant]

```tsx
import { ZapIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
  Popover,
  PopoverActions,
  PopoverClose,
  PopoverDescription,
  PopoverPopup,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover";

export default function Particle() {
  return (
    <Popover>
      <PopoverTrigger
        render={
          <Button variant="secondary">
            <ZapIcon />
            Quick tip
          </Button>
        }
      />
      <PopoverPopup colorScheme="vibrant">
        <PopoverTitle>Keyboard shortcuts</PopoverTitle>
        <PopoverDescription>
          Press Ctrl+Space inside Autocomplete inputs to open suggestions
          without a trigger button.
        </PopoverDescription>
        <PopoverActions>
          <PopoverClose render={<Button size="xs" />}>Nice</PopoverClose>
        </PopoverActions>
      </PopoverPopup>
    </Popover>
  );
}
```

### With Form [#with-form]

```tsx
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
  Popover,
  PopoverActions,
  PopoverClose,
  PopoverDescription,
  PopoverPopup,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/ui/popover";

export default function Particle() {
  return (
    <Popover>
      <PopoverTrigger
        render={<Button variant="outline">Invite member</Button>}
      />
      <PopoverPopup className="w-80">
        <PopoverTitle>Invite collaborator</PopoverTitle>
        <PopoverDescription>
          Send an invite link directly to their inbox.
        </PopoverDescription>
        <div className="mt-2">
          <Input placeholder="name@company.com" size="sm" type="email" />
        </div>
        <PopoverActions>
          <PopoverClose render={<Button size="xs" variant="ghost" />}>
            Cancel
          </PopoverClose>
          <PopoverClose render={<Button size="xs" />}>Send invite</PopoverClose>
        </PopoverActions>
      </PopoverPopup>
    </Popover>
  );
}
```

## API Reference [#api-reference]

### Popover [#popover]

Alias for `Popover.Root` from Base UI. Manages open state.

| Prop           | Type                      | Default | Description                                |
| -------------- | ------------------------- | ------- | ------------------------------------------ |
| `open`         | `boolean`                 | -       | Controlled open state                      |
| `defaultOpen`  | `boolean`                 | `false` | Initial uncontrolled open state            |
| `onOpenChange` | `(open: boolean) => void` | -       | Called when the open state changes         |
| `modal`        | `boolean`                 | `false` | Blocks interaction outside when `true`     |
| `...props`     | Base UI Popover Root props | -      | All other Popover Root props are supported |

### PopoverPopup [#popoverpopup]

The positioned floating container rendered inside a portal. Also exported as `PopoverContent`.

| Prop          | Type                                     | Default      | Description                                   |
| ------------- | ---------------------------------------- | ------------ | --------------------------------------------- |
| `colorScheme` | `"standard" \| "vibrant"`                | `"standard"` | Surface tint scheme                           |
| `side`        | `"top" \| "bottom" \| "left" \| "right"` | `"bottom"`   | Preferred side relative to the anchor         |
| `align`       | `"start" \| "center" \| "end"`           | `"center"`   | Alignment along the chosen side               |
| `sideOffset`  | `number`                                 | `8`          | Distance in pixels from the anchor            |
| `alignOffset` | `number`                                 | `0`          | Offset along the alignment axis               |
| `anchor`      | `Popover.Positioner.Props["anchor"]`     | -            | Custom anchor element                         |
| `portalProps` | `Popover.Portal.Props`                   | -            | Props forwarded to the internal portal        |
| `...props`    | Base UI Popover Popup props              | -            | All standard popover popup props              |

### PopoverTrigger / PopoverClose [#popovertrigger--popoverclose]

Trigger and dismiss primitives wrapping Base UI `Popover.Trigger` and `Popover.Close`.

### PopoverTitle / PopoverDescription [#popovertitle--popoverdescription]

Accessible heading and supporting description slots inside `PopoverPopup`.

### PopoverActions [#popoveractions]

Right-aligned action row at the bottom of `PopoverPopup` for buttons and `PopoverClose`.
