base-ui-svelte

Dialog

A window overlaid on the primary content for focused tasks.

View as Markdown

Sizes

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.

Dialog.Root

Groups all parts of the dialog. 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
modal DialogModal true
Name
modal
Description

Whether the dialog enters a modal state when open. - true: focus trap, aria-modal, document scroll locked, page interaction limited - false: no focus trap / aria-modal / scroll lock - 'trap-focus': focus trap without aria-modal or scroll lock

Type
DialogModal
Default
true
disablePointerDismissal boolean false
Description

Prevents closing on outside presses (and backdrop click).

Type
boolean
Default
false
onOpenChangeComplete function —
Description

Called after open/close animations complete.

Type
((open: boolean) => void) | undefined
handle DialogHandle —
Name
handle
Description

Imperative handle from .

Type
DialogHandle | 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.

Dialog.Backdrop

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

Props

render string —
Name
render
Description

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

Type
string
forceRender boolean false
Description

Keep the backdrop mounted while closed (for exit animations).

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

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

Dialog.Close

A button that closes the dialog. 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

Dialog.Description

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

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Dialog.Popup

A container for the dialog 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 dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog 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 dialog 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 dialog is closed.
data-ending-stylePresent when the dialog is animating out.
data-openPresent when the dialog is open.
data-starting-stylePresent when the dialog begins animating in.

Dialog.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

Dialog.Title

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

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Dialog.Trigger

A button that opens the dialog. 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 dialog in controlled mode (with the Dialog.Root triggerId prop).

Type
string | undefined
handle DialogHandle —
Name
handle
Description

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

Type
DialogHandle | undefined
payload unknown —
Name
payload
Description

Optional payload associated when opening via this trigger.

Type
unknown
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

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

Dialog.Viewport

A positioning container for the dialog popup that can be made scrollable. 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 dialog is closed.
data-openPresent when the dialog is open.