base-ui-svelte

Popover

Displays rich content in a portal, triggered by a button.

View as Markdown

API Reference

Props mirror Base UI React where applicable, adapted for Svelte 5. Native HTML attributes for the rendered element are also accepted unless noted.

Popover.Root

Groups all parts of the popover. Doesn't render its own HTML element.

Props

open boolean —
Name
open
Description

Whether the component is open (controlled).

Type
boolean | undefined
defaultOpen boolean false
Description

Whether the component is initially open (uncontrolled).

Type
boolean
Default
false
onOpenChange function —
Description

Event handler called when the open state changes.

Type
((open: boolean, eventDetails: { reason: OpenChangeReason }) => void)
| undefined
onOpenChangeComplete function —
Description

Event handler called after any animations complete when the popover is opened or closed.

Type
((open: boolean) => void) | undefined
openOnHover boolean —
Description

—

Type
boolean
delay number 0
Name
delay
Description

Open delay when openOnHover is set (ms).

Type
number
Default
0
closeDelay number 0
Description

Close delay when leaving under hover (ms).

Type
number
Default
0
modal PopoverModal false
Name
modal
Description

Whether the popover enters a modal state when open. - true: document scroll locked (except hover-open), outside interaction limited - false: no scroll lock - 'trap-focus': focus trap without scroll lock

Type
PopoverModal
Default
false
handle PopoverHandle —
Name
handle
Description

Imperative handle from .

Type
PopoverHandle | undefined
children snippet —
Description

Content rendered inside the part.

Type
Snippet<[{ open: boolean; payload: unknown }]>

Data attributes

AttributeDescription
data-closedPresent when the part is closed.
data-openPresent when the part is open.

Popover.Arrow

Displays an element positioned against the popover anchor. Renders a <div> element.

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the popup is closed.
data-openPresent when the popup is open.

Popover.Backdrop

An overlay displayed beneath the popover. Renders a <div> element.

Props

render string —
Name
render
Description

HTML element tag to render instead of the default host element.

Type
string
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the popup is closed.
data-ending-stylePresent when the popup is animating out.
data-openPresent when the popup is open.
data-starting-stylePresent when the popup begins animating in.

Popover.Close

A button that closes the popover. Renders a <button> element.

Props

render string —
Name
render
Description

HTML element tag to render instead of the default host element.

Type
string
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Popover.Description

A paragraph with additional information about the popover. Renders a <p> element.

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Popover.Popup

A container for the popover contents. Renders a <div> element.

Props

render string —
Name
render
Description

HTML element tag to render instead of the default host element.

Type
string
initialFocus FocusTarget —
Description

Determines the element to focus when the popover is opened. By default, focus moves to the first tabbable element inside the popup, except when the popover is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. false: Do not move focus.true: Move focus based on the default behavior (first tabbable element or popup).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.

Type
FocusTarget
finalFocus FocusTarget —
Description

Determines the element to focus when the popover is closed. false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.

Type
FocusTarget
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the popup is closed.
data-ending-stylePresent when the popup is animating out.
data-openPresent when the popup is open.
data-starting-stylePresent when the popup begins animating in.

Popover.Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Props

container HTMLElement | string | null —
Description

A parent element to render the portal element into.

Type
HTMLElement | string | null
keepMounted boolean false
Description

Whether to keep the portal mounted in the DOM while the popup is hidden.

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Popover.Positioner

Positions the popover against the trigger. Renders a <div> element.

Props

side ly o 'bottom'
Name
side
Description

Which side of the anchor element to align the popup against. May automatically change to avoid collisions.

Type
ly o
Default
'bottom'
align n; s 'center'
Name
align
Description

How to align the popup relative to the specified side.

Type
n; s
Default
'center'
sideOffset lean, 0
Description

Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.

Type
lean,
Default
0
alignOffset eReaso 0
Description

Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.

Type
eReaso
Default
0
collisionPadding erDelay(reason: OpenChang… 5
Description

Additional space to maintain from the edge of the collision boundary.

Type
erDelay(reason: OpenChangeReason): voi
Default
5
collisionBoundary (reason: OpenCh 'clipping-ancestors'
Description

An element or a rectangle that delimits the area that the popup is confined to.

Type
(reason: OpenCh
Default
'clipping-ancestors'
collisionAvoidance elHover(): void; —
Description
  • Determines how to handle collisions when positioning the popup. side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side
  • (top and bottom, or left and right).
  • 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.
  • 'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.
  • 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.
  • 'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first
  • (top before bottom, or left before right in LTR).
  • 'end': allow perpendicular fallback and try the logical end side first
  • (bottom before top, or right before left in LTR).
  • 'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'.
  • If align is omitted, it defaults to 'flip'.
Type
elHover(): void;
arrowPadding er: bo 5
Description

Minimum distance to maintain between the arrow and the edges of the popup. Use it to prevent the arrow element from hanging out of the rounded corners of a popup.

Type
er: bo
Default
5
sticky only de false
Name
sticky
Description

Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.

Type
only de
Default
false
positionMethod ly lastOpenChangeR 'absolute'
Description

Maps to Floating UI strategy (absolute | fixed).

Type
ly lastOpenChangeR
Default
'absolute'
strategy descriptionId: str —
Description

—

Type
descriptionId: str
anchor eturnType<typeof createPr… —
Name
anchor
Description

Override the positioning anchor (element or virtual element).

Type
eturnType<typeof createPresence
disableAnchorTracking olean, false
Description

When true, skip continuous layout tracking of the anchor (position once; no resize/scroll auto-updates beyond the initial compute).

Type
olean,
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the popup is closed.
data-openPresent when the popup is open.

Popover.Title

A heading that labels the popover. Renders an <h2> element.

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Popover.Trigger

A button that opens the popover. Renders a <button> element.

Props

render string —
Name
render
Description

HTML element tag to render instead of the default host element.

Type
string
disabled boolean false
Description

Whether the control ignores user interaction.

Type
boolean
Default
false
id string —
Name
id
Description

ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the popover in controlled mode (with the Popover.Root triggerId prop).

Type
string | undefined
handle PopoverHandle —
Name
handle
Description

Same handle as Root — enables triggers outside the Root tree.

Type
PopoverHandle | undefined
payload unknown —
Name
payload
Description

Optional payload associated when opening via this trigger.

Type
unknown
openOnHover boolean false
Description

Whether the popover should also open when the trigger is hovered.

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the part is closed.
data-disabledPresent when the part is disabled.
data-openPresent when the part is open.

Popover.Viewport

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.

Props

render string —
Name
render
Description

HTML element tag to render instead of the default host element.

Type
string
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-closedPresent when the part is closed.
data-openPresent when the part is open.