Skip to Content
Zuri
Components

Popover

A panel anchored to its trigger that can hold interactive content, built on Radix.

Live preview
Theme
Preview width

Use Popover for a small panel tied to a control, such as filters, a date picker or a share menu. Unlike a Tooltip it can contain buttons and fields. Unlike a Dialog it does not block the page.

Installation

pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/popover.json

This adds one dependency, @radix-ui/react-popover, which the command installs for you.

Usage

import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";

<Popover>
  <PopoverTrigger>Filters</PopoverTrigger>
  <PopoverContent aria-label="Filters">…</PopoverContent>
</Popover>

Place it with side, align and sideOffset. It flips to the other side when there is not enough room, and keeps 8 pixels from the screen edge.

Props

PopoverContent takes the Radix content props. Popover takes open, defaultOpen and onOpenChange.

Props
PropTypeDefaultDescription
variant"default" | "glass""default"On PopoverContent. Visual style of the panel.
side / align"top" | "right" | "bottom" | "left" / "start" | "center" | "end""bottom" / "center"Where it appears relative to the trigger.
sideOffsetnumber8Gap from the trigger in pixels.
open / defaultOpen / onOpenChangeboolean / boolean / (open: boolean) => void–On Popover. Controlled and uncontrolled use.

Accessibility

  • After a mouse click, focus returns to the button that opened it without drawing a focus ring (no stray border); after a key press the ring shows as normal. This comes from the small focus-modality helper, which installs with this component.
  • The trigger is a native button with aria-expanded. Enter and Space open it.
  • Focus moves into the panel when it opens and returns to the trigger on close. Escape and an outside click close it.
  • Give the content an accessible name: a heading inside it, or aria-label as in the example.
  • The panel is a dialog-role region that does not trap focus, so Tab can leave it. Put long forms in a Dialog instead.

Tokens used

--background, --foreground, --border, --shadow-lg look, --duration-fast, --ease-out, --z-dropdown, and the glass variables.

Known limitations

  • No exit animation: it unmounts when closed.
  • Glass text contrast has not been measured against worst-case backdrops.

Source

"use client";import * as PopoverPrimitive from "@radix-ui/react-popover";import { cva, type VariantProps } from "class-variance-authority";import type { ComponentProps } from "react";import { useQuietFocusRestore } from "@/lib/focus-modality";import { cn } from "@/lib/utils";/** Compose with PopoverTrigger and PopoverContent. */export const Popover = PopoverPrimitive.Root;export const PopoverTrigger = PopoverPrimitive.Trigger;export const PopoverClose = PopoverPrimitive.Close;export const PopoverAnchor = PopoverPrimitive.Anchor;const contentVariants = cva(  "z-[var(--z-dropdown)] w-72 max-w-[calc(100vw-1rem)] max-h-[var(--radix-popover-content-available-height)] overflow-y-auto rounded-xl p-4 text-sm text-foreground transition-[opacity,transform,translate,scale,rotate] duration-[var(--duration-fast)] ease-[var(--ease-out)] starting:scale-95 starting:opacity-0 focus-visible:outline-none",  {    variants: {      variant: {        default: "border border-border bg-background shadow-lg",        glass: "zuri-glass",      },    },    defaultVariants: { variant: "default" },  },);export interface PopoverContentProps  extends ComponentProps<typeof PopoverPrimitive.Content>,    VariantProps<typeof contentVariants> {}/** * A small panel anchored to its trigger. Unlike a tooltip it can hold interactive content. * Radix moves focus into it, closes it on Escape or an outside click, and returns focus to * the trigger. Give the content an accessible name (a heading, or `aria-label`). */export function PopoverContent({  className,  variant,  sideOffset = 8,  collisionPadding = 8,  children,  onCloseAutoFocus,  ...props}: PopoverContentProps) {  const quiet = useQuietFocusRestore(onCloseAutoFocus);  return (    <PopoverPrimitive.Portal>      <PopoverPrimitive.Content        sideOffset={sideOffset}        collisionPadding={collisionPadding}        className={cn(contentVariants({ variant }), className)}        onCloseAutoFocus={quiet.onCloseAutoFocus}        {...props}      >        <span hidden ref={quiet.probe} />        {children}      </PopoverPrimitive.Content>    </PopoverPrimitive.Portal>  );}export { contentVariants as popoverContentVariants };

On this page