Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Popover for Solid

A panel that opens beside its button for a quick edit or a short note, and closes on Escape or a click outside. A Solid popover on Ark UI.

On this page9 sections
UI library: Ark UI

A popover is a small panel that opens beside the button that pressed it, for a short note, a couple of settings or a quick edit such as a layer's width and height. Focus moves into it when it opens, and Escape or a click outside closes it.

When the task needs the whole screen and an explicit Cancel, use a Dialog. For a one-line hint that shows on hover or focus and holds nothing to click, a Tooltip is lighter.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Popover anatomy: trigger, title, positioner, arrow, description, content

Usage

import { Button } from "@/components/ui/button";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
  Popover, PopoverContent, PopoverDescription, PopoverHeader,
  PopoverTitle, PopoverTrigger,
} from "@/components/ui/popover";
<Popover>
  <PopoverTrigger
    asChild={(props) => (
      <Button {...props()} variant="outline">Open popover</Button>
    )}
  />
  <PopoverContent class="w-64 max-w-full">
    <PopoverHeader>
      <PopoverTitle>Dimensions</PopoverTitle>
      <PopoverDescription>
        Set the dimensions for the layer.
      </PopoverDescription>
    </PopoverHeader>
    <FieldGroup class="min-w-0 gap-3">
      <Field class="min-w-0" orientation="horizontal">
        <FieldLabel class="w-1/2">Width</FieldLabel>
        <Input class="min-w-0" defaultValue="100%" />
      </Field>
      <Field class="min-w-0" orientation="horizontal">
        <FieldLabel class="w-1/2">Height</FieldLabel>
        <Input class="min-w-0" defaultValue="25px" />
      </Field>
    </FieldGroup>
  </PopoverContent>
</Popover>

Accessibility

The trigger is a button with aria-expanded and aria-haspopup="dialog", and the panel is a role="dialog" named by PopoverTitle and described by PopoverDescription. This file makes the popover modal: focus goes to the first field inside and stays there, the page behind it is hidden from screen readers and can't scroll, and closing returns focus to the trigger. Give every popover a PopoverTitle, or an aria-label on PopoverContent when it has none.

Space
Opens/closes the popover.
Enter
Opens/closes the popover.
Tab
Moves focus to the next focusable element within the content, and from the last one back to the first. With nothing focusable inside, focus stays on the content.
Shift+Tab
Moves focus to the previous focusable element within the content, and from the first one to the last.
Escape
Closes the popover and moves focus to the trigger.

Demos

Basic

A title, Dimensions, and one line of description, with no fields under them. The panel lines up with the start of the button instead of its center, so it reads as a note pinned to that control. Pick this shape for a definition, a status or a short explanation that someone reads and then dismisses with Escape or a click elsewhere.

Preview width

Alignments

Three small buttons, Start, Center and End, each open a narrow panel lined up with that edge of the button. The edge comes from placement in the positioning prop on Popover: bottom-start, bottom or bottom-end. Near the edge of the screen, align toward the inside, and keep one alignment across a toolbar so its panels don't jump around.

Preview width

Form

The Dimensions panel as a small form, with Width and Height fields, Cancel and Save. The demo holds the open state, so Save, or Enter in a field, stores the size shown beside the trigger and closes the popover. Cancel is a PopoverClose, which closes it without saving. A longer form, or one that must be finished first, belongs in a Dialog.

Preview width

RTL

Arabic buttons inside a Direction provider set to right to left, which makes Ark UI write dir on the portaled panel too. Four buttons set placement to left, top, bottom and right. placement only takes physical sides, so the second row maps the start of the line to right and its end to left.

Preview width

FAQ

When should I use a Popover instead of a Dialog, a Tooltip or a Hover Card?

Use a Popover for a short form or a few controls that belong to the button that opened them, such as a column filter, a share link or the size of a layer. It opens on a click and closes when people are done with it.

A Dialog is for a task that takes over the screen until it's finished or canceled. A Tooltip shows a short label on hover or focus and can't hold anything clickable. A Hover Card previews a profile or a link while the pointer rests on it.

How do I open or close a Popover from code in Solid?

Keep a boolean in state, pass it as open on Popover and update it in onOpenChange. The callback receives an object, so read the next state from details.open.

The trigger still has to be there, since the panel positions itself against it. Once the state is yours, a keyboard shortcut or a step in an onboarding tour can open the popover too.

How do I close a Popover after saving the form inside it?

Control the open state, as the answer above describes, and set it to closed in the form's submit handler once the save succeeds, as the Form demo does. If the save fails, leave it open so the error shows next to the fields.

For a Cancel button, use PopoverClose, a button that closes the popover without any state of yours. Setting showCloseButton on PopoverContent adds one as an X in the corner.

Does a Popover block the rest of the page while it's open?

In this file it does: Popover sets modal to true unless you say otherwise. Focus is trapped in the panel, the page can't scroll, the rest is hidden from screen readers, and a click outside closes the popover without reaching what was under the pointer. Set modal to false for a panel that sits beside a page people keep using.

How do I align a Popover to the start or end of its trigger?

Set placement in the positioning prop on Popover: bottom-start, bottom (the default) or bottom-end, and the same suffixes on top, left and right. gutter in the same object sets the gap between the trigger and the panel.

The Alignments demo puts all three side by side. When there isn't room, the panel flips to the other side on its own.

How do I make a Popover as wide as its trigger?

Give the panel a width from the CSS variable that holds the trigger's width. On PopoverContent that is w-(--reference-width), which Ark UI sets on the positioner around it.

The class replaces the w-72 this file starts with, and the value follows the trigger when it resizes. Keep the max-w class too, so a wide trigger doesn't push the panel off a phone screen.

How do I position a Popover against a different element than its trigger?

Wrap that element in PopoverAnchor. The trigger still opens and closes the popover, and the panel positions itself against the anchor instead, which suits a button that edits a field or a row sitting elsewhere in the layout.

How do I give a Popover an accessible name in Ark UI?

Put a PopoverTitle in it. The panel points aria-labelledby at the title, and aria-describedby at a PopoverDescription, so a screen reader announces both when focus moves in. A panel with no visible title needs an aria-label on PopoverContent instead.

API Reference

Popover

data-slot="popover"

PropType
open?boolean

The controlled open state of the popover.

defaultOpen?boolean

The initial open state of the popover when rendered. Use when you don't need to control the open state of the popover.

onOpenChange?(details: OpenChangeDetails) → void

Function invoked when the popover opens or closes.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
triggerValue?string | null

The controlled trigger value.

Type
string | null
defaultTriggerValue?string | null

The initial trigger value when rendered. Use when you don't need to control the trigger value.

Type
string | null
onTriggerValueChange?(details: TriggerValueChangeDetails) → void

Function called when the trigger value changes.

Type
(details: TriggerValueChangeDetails) → void
Parameters

details – { value: string | null; triggerElement: HTMLElement | null }

Returns
void
autoFocus?boolean

Whether to automatically set focus on the first focusable content within the popover when opened.

Default
true
closeOnEscape?boolean

Whether to close the popover when the escape key is pressed.

Default
true
closeOnInteractOutside?boolean

Whether to close the popover when the user clicks outside of the popover.

Default
true
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
finalFocusEl?() → MaybeElement

Element to receive focus when the popover is closed.

Returns
MaybeElement
hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the popover. Useful for composition.

Type
{ anchor?: string; trigger?: string | ((value?: string) → string); content?: string; title?: string; description?: string; closeTrigger?: string; positioner?: string; arrow?: string }
immediate?boolean

Whether to synchronize the present change immediately or defer it to the next frame.

initialFocusEl?() → HTMLElement | null | false

The element to focus on when the popover is opened. Return false to skip moving focus, or null to use the default.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
lazyMount?boolean

Whether to enable lazy mounting. Ark default: false.

Default
true
modal?boolean

Whether the popover should be modal. When set to true: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover Ark default: false.

Default
true
onEnterComplete?VoidFunction

Function called when the animation ends in the open state.

onEscapeKeyDown?(event: KeyboardEvent) → void

Function called when the escape key is pressed.

Parameters

event – { altKey: boolean; charCode: number; ctrlKey: boolean; code: string; getModifierState: (key: string) → boolean; key: string; keyCode: number; locale: string; location: number; metaKey: boolean; repeat: boolean; shiftKey: boolean; which: number }

Returns
void
onExitComplete?VoidFunction

Function called when the animation ends in the closed state.

onFocusOutside?(event: FocusOutsideEvent) → void

Function called when the focus is moved outside the component.

Type
(event: FocusOutsideEvent) → void
Parameters

event – FocusOutsideEvent

Returns
void
onInteractOutside?(event: InteractOutsideEvent) → void

Function called when an interaction happens outside the component.

Type
(event: InteractOutsideEvent) → void
Parameters

event – InteractOutsideEvent

Returns
void
onPointerDownOutside?(event: PointerDownOutsideEvent) → void

Function called when the pointer is pressed down outside the component.

Type
(event: PointerDownOutsideEvent) → void
Parameters

event – PointerDownOutsideEvent

Returns
void
onRequestDismiss?(event: LayerDismissEvent) → void

Function called when this layer is closed due to a parent layer being closed.

Type
(event: LayerDismissEvent) → void
Parameters

event – LayerDismissEvent

Returns
void
persistentElements?Array<() → Element | null>

Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event

Type
Array<() → Element | null>
portalled?boolean

Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.

Default
true
positioning?object

The user provided options used to position the popover content.

Type
{ restoreStyles?: boolean; applyStyles?: boolean; hideWhenDetached?: boolean; strategy?: "absolute" | "fixed"; placement?: Placement; offset?: { mainAxis?: number; crossAxis?: number; }; gutter?: number; shift?: number; overflowPadding?: number; arrowPadding?: number; flip?: boolean | Placement[]; slide?: boolean; overlap?: boolean; sameWidth?: boolean; fitViewport?: boolean; sizeMiddleware?: boolean; boundary?: (() → Boundary) | Boundary | "clipping-ancestors"; listeners?: boolean | AutoUpdateOptions; onComplete?: (data: ComputePositionReturn) → void; onPositioned?: ((data: { placed: boolean; }) → void); getAnchorElement?: () → HTMLElement | VirtualElement | null; getAnchorRect?: (element: HTMLElement | VirtualElement | null) → AnchorRect | null; updatePosition?: ((data: { updatePosition: () → Promise<void>; floatingElement: HTMLElement | null; }) → void | Promise<void>) }
present?boolean

Whether the node is present (controlled by the user).

restoreFocus?boolean

Whether to restore focus to the element that had focus before the popover was opened.

Default
true
skipAnimationOnMount?boolean

Whether to allow the initial presence animation.

Default
false
translations?object

Specifies the localized strings that identifies the accessibility elements and their states.

Type
{ closeTriggerLabel?: string }
unmountOnExit?boolean

Whether to unmount on exit. Ark default: false.

Default
true

PopoverArrow

<div> data-slot="popover-arrow"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

CSS variableType
--arrow-backgroundstring

Use this variable to style the arrow background.

--arrow-offsetstring

The offset position of the arrow.

--arrow-sizestring

The size of the arrow.

--arrow-size-halfstring

Half the size of the arrow.

PopoverArrowTip

<div>

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element

PopoverAnchor

<div> data-slot="popover-anchor"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element

PopoverTrigger

<button> data-slot="popover-trigger"

PropType
value?string

The value that identifies this specific trigger.

asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-current?string

Present when current.

data-placement?string

The placement of the trigger.

data-side?string

The side of the trigger that the trigger is positioned on.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
data-value?string

The value of the item.

PopoverPositioner

<div> data-slot="popover-positioner"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-has-nested?string

Present when the positioner has nested popovers.

data-nested?string

Present when the positioner is nested within another popover.

CSS variableType
--available-heightstring

The available height in viewport.

--available-widthstring

The available width in viewport.

--reference-heightstring

The height of the root.

--reference-widthstring

The width of the reference element.

--transform-originstring

The transform origin for animations.

--xstring

The x position for transform.

--ystring

The y position for transform.

--z-indexstring

The z-index value.

PopoverContent

<div> data-slot="popover-content"

PropType
showCloseButton?boolean

Show a close button in the top corner at the end of the line (top right in left-to-right text)

Default
false
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-expanded?string

Present when expanded.

data-has-nested?string

Present when another popover is nested inside it.

data-nested?string

Present when it's nested inside another popover.

data-placementstring

The placement of the content.

data-side"top" | "right" | "bottom" | "left"

The side of the trigger that the content is positioned on.

Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
CSS variableType
--layer-indexstring

The index of the dismissable in the layer stack.

--nested-layer-countstring

The number of nested popovers.

--transform-originstring

Where the content scales from, on its trigger's side.

PopoverTitle

<h2> data-slot="popover-title"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

PopoverDescription

<div> data-slot="popover-description"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

PopoverClose

<button> data-slot="popover-close-trigger"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element

PopoverHeader

<div> data-slot="popover-header"

PropType
description?string

The description of the popover header.

title?string

The title of the popover header.

asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

PopoverBody

<div> data-slot="popover-body"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

CSS variableType
--spacestring

PopoverFooter

<div> data-slot="popover-footer"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

CSS variableType
--spacestring

usePopover

PropType
open?boolean

The controlled open state of the popover.

defaultOpen?boolean

The initial open state of the popover when rendered. Use when you don't need to control the open state of the popover.

onOpenChange?(details: OpenChangeDetails) → void

Function invoked when the popover opens or closes.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
triggerValue?string | null

The controlled trigger value.

Type
string | null
defaultTriggerValue?string | null

The initial trigger value when rendered. Use when you don't need to control the trigger value.

Type
string | null
onTriggerValueChange?(details: TriggerValueChangeDetails) → void

Function called when the trigger value changes.

Type
(details: TriggerValueChangeDetails) → void
Parameters

details – { value: string | null; triggerElement: HTMLElement | null }

Returns
void
autoFocus?boolean

Whether to automatically set focus on the first focusable content within the popover when opened.

Default
true
closeOnEscape?boolean

Whether to close the popover when the escape key is pressed.

Default
true
closeOnInteractOutside?boolean

Whether to close the popover when the user clicks outside of the popover.

Default
true
finalFocusEl?() → MaybeElement

Element to receive focus when the popover is closed.

Returns
MaybeElement
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the popover. Useful for composition.

Type
{ anchor?: string; trigger?: string | ((value?: string) → string); content?: string; title?: string; description?: string; closeTrigger?: string; positioner?: string; arrow?: string }
initialFocusEl?() → HTMLElement | null | false

The element to focus on when the popover is opened. Return false to skip moving focus, or null to use the default.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
modal?boolean

Whether the popover should be modal. When set to true: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover

Default
false
onEscapeKeyDown?(event: KeyboardEvent) → void

Function called when the escape key is pressed.

Parameters

event – { altKey: boolean; charCode: number; ctrlKey: boolean; code: string; getModifierState: (key: string) → boolean; key: string; keyCode: number; locale: string; location: number; metaKey: boolean; repeat: boolean; shiftKey: boolean; which: number }

Returns
void
onFocusOutside?(event: FocusOutsideEvent) → void

Function called when the focus is moved outside the component.

Type
(event: FocusOutsideEvent) → void
Parameters

event – FocusOutsideEvent

Returns
void
onInteractOutside?(event: InteractOutsideEvent) → void

Function called when an interaction happens outside the component.

Type
(event: InteractOutsideEvent) → void
Parameters

event – InteractOutsideEvent

Returns
void
onPointerDownOutside?(event: PointerDownOutsideEvent) → void

Function called when the pointer is pressed down outside the component.

Type
(event: PointerDownOutsideEvent) → void
Parameters

event – PointerDownOutsideEvent

Returns
void
onRequestDismiss?(event: LayerDismissEvent) → void

Function called when this layer is closed due to a parent layer being closed.

Type
(event: LayerDismissEvent) → void
Parameters

event – LayerDismissEvent

Returns
void
persistentElements?Array<() → Element | null>

Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event

Type
Array<() → Element | null>
portalled?boolean

Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.

Default
true
positioning?object

The user provided options used to position the popover content.

Type
{ restoreStyles?: boolean; applyStyles?: boolean; hideWhenDetached?: boolean; strategy?: "absolute" | "fixed"; placement?: Placement; offset?: { mainAxis?: number; crossAxis?: number; }; gutter?: number; shift?: number; overflowPadding?: number; arrowPadding?: number; flip?: boolean | Placement[]; slide?: boolean; overlap?: boolean; sameWidth?: boolean; fitViewport?: boolean; sizeMiddleware?: boolean; boundary?: (() → Boundary) | Boundary | "clipping-ancestors"; listeners?: boolean | AutoUpdateOptions; onComplete?: (data: ComputePositionReturn) → void; onPositioned?: ((data: { placed: boolean; }) → void); getAnchorElement?: () → HTMLElement | VirtualElement | null; getAnchorRect?: (element: HTMLElement | VirtualElement | null) → AnchorRect | null; updatePosition?: ((data: { updatePosition: () → Promise<void>; floatingElement: HTMLElement | null; }) → void | Promise<void>) }
restoreFocus?boolean

Whether to restore focus to the element that had focus before the popover was opened.

Default
true
translations?object

Specifies the localized strings that identifies the accessibility elements and their states.

Type
{ closeTriggerLabel?: string }