base-ui-svelte

Collapsible

An interactive component which expands/collapses a panel.

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.

Collapsible.Root

Groups all parts of the collapsible. Renders a <div> 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
disabled boolean false
Description

Whether the control ignores user interaction.

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet<[{ open: boolean }]>

Data attributes

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

Collapsible.Panel

A panel with the collapsible contents. Renders a <div> element.

Props

keepMounted boolean false
Description

Whether to keep the element in the DOM while the panel is hidden. This prop is ignored when hiddenUntilFound is used.

Type
boolean
Default
false
role string —
Name
role
Description

—

Type
string | undefined
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

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

Collapsible.Trigger

A button that opens and closes the collapsible panel. Renders a <button> element.

Props

children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-disabledPresent when the part is disabled.
data-panel-openPresent when the collapsible panel is open.