Skip to content
All components
Overlays

Popover

Show a small, non-modal piece of interactive content anchored to the control that opened it, without taking the user out of the page.

Floating content anchored to a trigger.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add popover

Then import it from @/components/ui/popover. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Share link top

Place a labelled popover above its trigger, aligned to the start edge. The content is named by its visible heading through aria-labelledby; collision handling may still flip it.

"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"

export function PopoverShareLinkTop() {
  const id = React.useId()
  
  
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Popover>
        <PopoverTrigger asChild>
          <Button intent="neutral" emphasis="stroke">
            Share link
          </Button>
        </PopoverTrigger>
        <PopoverContent side="top" align="start" aria-labelledby={`${id}-share-title`}>
          <p id={`${id}-share-title`} className="text-label-sm text-strong-950">
            Share link
          </p>
          <p className="mt-1 text-paragraph-sm text-sub-600">
            Anyone with the link can view this page.
          </p>
          <div className="mt-3 flex flex-col gap-1.5">
            <Label htmlFor={`${id}-share-url`}>Page link</Label>
            <Input id={`${id}-share-url`} readOnly defaultValue="https://example.com/p/42" />
          </div>
        </PopoverContent>
      </Popover>
    </div>
  )
}

Controlled form

Own the open state in the parent and close the popover after a small form is applied. Cancel and Escape close without applying; the trigger label reflects the applied value.

"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"

export function PopoverControlledForm() {
  const id = React.useId()
  const [filtersOpen, setFiltersOpen] = React.useState(false)
  const [owner, setOwner] = React.useState("")
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Popover open={filtersOpen} onOpenChange={setFiltersOpen}>
        <PopoverTrigger asChild>
          <Button intent="neutral" emphasis="stroke">
            {owner ? `Owner: ${owner}` : "Filter by owner"}
          </Button>
        </PopoverTrigger>
        <PopoverContent align="start" aria-labelledby={`${id}-filter-title`}>
          <form
            onSubmit={(event) => {
              event.preventDefault()
              const value = new FormData(event.currentTarget).get("owner")
              setOwner(typeof value === "string" ? value.trim() : "")
              setFiltersOpen(false)
            }}
          >
            <p id={`${id}-filter-title`} className="text-label-sm text-strong-950">
              Filter by owner
            </p>
            <div className="mt-3 flex flex-col gap-1.5">
              <Label htmlFor={`${id}-owner`}>Owner name</Label>
              <Input id={`${id}-owner`} name="owner" defaultValue={owner} />
            </div>
            <div className="mt-3 flex justify-end gap-2">
              <Button type="button" size="sm" intent="neutral" emphasis="ghost" onClick={() => setFiltersOpen(false)}>
                Cancel
              </Button>
              <Button type="submit" size="sm">
                Apply filter
              </Button>
            </div>
          </form>
        </PopoverContent>
      </Popover>
    </div>
  )
}

Anchored to field

Anchor the popover to a whole field while an icon button opens it. PopoverAnchor positions the content; the trigger keeps its own accessible name.

"use client"

import * as React from "react"
import { InfoIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import {
  Popover,
  PopoverAnchor,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"

export function PopoverAnchoredToField() {
  const id = React.useId()
  
  
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Popover>
        <PopoverAnchor asChild>
          <div className="flex w-full max-w-xs items-end gap-2">
            <div className="flex flex-1 flex-col gap-1.5">
              <Label htmlFor={`${id}-password`}>New password</Label>
              <Input id={`${id}-password`} type="password" autoComplete="new-password" />
            </div>
            <PopoverTrigger asChild>
              <Button iconOnly intent="neutral" emphasis="ghost" aria-label="Password requirements">
                <InfoIcon />
              </Button>
            </PopoverTrigger>
          </div>
        </PopoverAnchor>
        <PopoverContent align="start" aria-label="Password requirements">
          <ul className="flex list-disc flex-col gap-1 ps-4 text-paragraph-sm text-sub-600">
            <li>At least 12 characters</li>
            <li>Not a password you use elsewhere</li>
            <li>Spaces and symbols are allowed</li>
          </ul>
        </PopoverContent>
      </Popover>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Popover

Present contextual interactive content anchored to a trigger.

Popover props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (4)
Popover inherited props
PropTypeDefaultDescription
openboolean | undefined—Controlled visibility state. Pair with onOpenChange so requested state changes can be applied.
defaultOpenboolean | undefined—Initial uncontrolled visibility state. Later changes use the primitive's controls or controlled open API.
onOpenChange((open: boolean) => void) | undefined—Receive the requested open state. Apply it to open when controlled.
modalboolean | undefined—Whether this overlay uses modal behavior. Preserve the corresponding background interaction and focus behavior.

PopoverAnchor

The PopoverAnchor part of popover. Use it with the complete source composition and preserve its required parent context.

PopoverAnchor props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (15)
PopoverAnchor inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
virtualRefReact.RefObject<import("@radix-ui/rect").Measurable | null> | undefined—Reference to a virtual positioning anchor instead of a visible DOM anchor.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

PopoverContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

PopoverContent props
PropTypeDefaultDescription
forceMounttrue | undefined—Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
deferPointerDownOutsideboolean | undefined—When true, a 'pointerdown' event outside of the layered element will wait for the interaction's click event before dispatching, allowing third-party code to stop propagation of later events and cancel dismissal.
onEscapeKeyDown((event: KeyboardEvent) => void) | undefined—Event handler called when the escape key is down. Can be prevented.
onPointerDownOutside((event: CustomEvent<{ originalEvent: PointerEvent; }>) => void) | undefined—Event handler called when the a pointerdown event happens outside of the DismissableLayer. Can be prevented.
onFocusOutside((event: CustomEvent<{ originalEvent: FocusEvent; }>) => void) | undefined—Event handler called when the focus moves outside of the DismissableLayer. Can be prevented.
onInteractOutside((event: CustomEvent<{ originalEvent: PointerEvent; }> | CustomEvent<{ originalEvent: FocusEvent; }>) => void) | undefined—Event handler called when an interaction happens outside the DismissableLayer. Specifically, when a pointerdown event happens outside or focus moves outside of it. Can be prevented.
onOpenAutoFocus((event: Event) => void) | undefined—Event handler called when auto-focusing on open. Can be prevented.
onCloseAutoFocus((event: Event) => void) | undefined—Event handler called when auto-focusing on close. Can be prevented.
Inherited props (25)
PopoverContent inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
side"top" | "right" | "bottom" | "left" | undefined—Preferred side relative to the trigger. Collision handling can adjust the final placement where supported.
sideOffsetnumber | undefined6Spacing between the floating content and its trigger along the placement axis.
align"center" | "start" | "end" | undefined"center"Alignment of floating content relative to its trigger, using the supported source values.
alignOffsetnumber | undefined—Offset from the selected floating-content alignment.
arrowPaddingnumber | undefined—Minimum spacing between a floating arrow and the content's edges.
avoidCollisionsboolean | undefined—Allow floating content to adjust placement to avoid its collision boundary.
collisionBoundary(Element | null) | (Element | null)[] | undefined—Element or elements used as the boundary for floating-content collision checks.
collisionPaddingnumber | Partial<Record<"top" | "right" | "bottom" | "left", number>> | undefined—Space reserved between floating content and its collision boundary.
sticky("partial" | "always") | undefined—How floating content remains attached to its trigger while collision positioning is constrained.
hideWhenDetachedboolean | undefined—Hide floating content when its trigger becomes detached from the positioning boundary.
updatePositionStrategy("always" | "optimized") | undefined—Optimized or continuous updates to floating-content positioning, as supported by the primitive.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

PopoverTrigger

Interactive control that opens or toggles the associated content. Preserve its accessible name and the required root context.

PopoverTrigger props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (19)
PopoverTrigger inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/popover.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Adjust one or two values in place, such as a size, a filter or a date, where the result is visible right next to the trigger.
  • Show a short share link, a set of quick options or a compact form that the user opens on purpose with a click or Enter.
  • Anchor the content to a larger area than the button with PopoverAnchor, for example a whole field whose help icon opens it.
  • Own the open state with open and onOpenChange when an action inside (Apply, Save) should close the popover after it succeeds.

When not to use

  • A label or one-line explanation of a control; that is a tooltip and should not require a click.
  • A decision the user must make before continuing, such as a destructive confirmation; use an alert dialog.
  • A multi-step task, long form or anything that needs scrolling inside the overlay; use a dialog, or a sheet or drawer on small screens.
  • A list of commands; menus give the expected arrow-key navigation and roles.

Anatomy

Popover
Root. Holds open state, uncontrolled (defaultOpen) or controlled (open plus onOpenChange); non-modal by default.
PopoverTrigger
The control that toggles the content; usually a Button through asChild. Exposes aria-expanded and aria-controls.
PopoverAnchor
Optional element the content is positioned against instead of the trigger, such as a whole field row.
PopoverContent
Portaled panel with the dialog role. Positioned by side, align (default center) and sideOffset (default 6); flips and shifts to stay in the viewport. Needs an accessible name.

Keyboard & interaction

  • Click, Enter or Space on the trigger opens the content and moves focus into it, normally to the first focusable control.
  • Escape closes it and returns focus to the trigger; a pointer press or focus outside also closes it.
  • Because it is non-modal, Tab from the last control leaves the popover and continues in page order; the page behind stays readable and operable.
  • In controlled mode, close it from the parent after an inner action completes, and make sure focus lands back on the trigger or a sensible next control (WCAG 2.4.3).
  • The panel flips to the opposite side or shifts along its edge when there is not enough room (collision handling is on by default).

Responsive behavior

  • The default width (w-72, 288px) fits a 320px viewport with the default offset; wider content must use max-width and wrap rather than overflow (WCAG 1.4.10).
  • On touch screens a popover opened near the bottom can be covered by the on-screen keyboard; for inputs on mobile prefer a drawer or a dialog.
  • Keep the trigger at least 24x24 CSS pixels (WCAG 2.5.8); icon-only triggers in dense toolbars need extra spacing.
  • Do not rely on a specific side; collision handling may move it, so the content must make sense on any side of the trigger.

Content guidelines

  • Give the panel a short title that matches the trigger label ('Share link', 'Filter by owner') and use it as the accessible name.
  • Keep the content to one task and a few controls; if it needs a scroll or more than one primary action, use a dialog.
  • When an inner action applies a change, name the outcome ('Apply filter') and reflect the applied value on the trigger label.
  • Closing by Escape or outside click discards unapplied input; say so if values are only saved by an explicit action.

Alternatives

  • Tooltip — A short, non-interactive description shown on hover and focus.
  • Hover card — An optional preview behind a link that opens on hover or focus, with no controls inside.
  • Dropdown menu — A set of actions or menu choices behind one button, with menu keyboard navigation.
  • Dialog — A focused modal task that needs a title, a description and containment of focus.
  • Drawer — The same small task on touch screens, where an anchored overlay is cramped.

Resources