Collapsible
A collapsible panel controlled by a button.
Anatomy
Import the component and assemble its parts:
Examples
Hidden until found
The hiddenUntilFound prop hides the closed panel with hidden="until-found" so the browser can search its contents with find-in-page—Ctrl+F (Cmd+F on macOS)—and reveal the panel when a match is found. The closed panel always remains mounted in the DOM, which also makes its contents indexable by search engines.
Older browsers that don't support hidden="until-found" keep the panel hidden until its trigger opens it, and find-in-page skips over the contents.
See the Accordion example for an interactive demo.
API reference
Root
Groups all parts of the collapsible. Renders a <div> element.
open boolean false
- Name
- Description
Whether the panel is open. Use
bind:opento share it with the parent. A value passed withoutbind:holds until the parent changes it.- Type
boolean- Default
false- Binding
bind:open
disabled boolean | null false
- Name
- Description
Whether the collapsible should ignore user interaction.
- Type
boolean | null- Default
false
onOpenChange function —
- Name
- Description
Called before the open state changes. Call
eventDetails.cancel()to veto it.- Type
(open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CollapsibleRootState, children: Snippet | undefined]> —
- Name
- Description
Replace the default
<div>. Spreadpropsonto the host and renderchildren.- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CollapsibleRootState, children: Snippet | undefined]>
open boolean
- Name
open- Description
Whether the panel is currently open.
- Type
boolean
disabled boolean
- Name
disabled- Description
Whether the collapsible should ignore user interaction.
- Type
boolean
transitionStatus TransitionStatus
- Name
transitionStatus- Description
Shared open/close motion phase.
- Type
TransitionStatus
data-open
data-closed
data-disabled
data-starting-style
data-ending-style
Trigger
A button that opens and closes the collapsible panel. Renders a <button> element.
disabled boolean | null —
- Name
- Description
Whether the trigger should ignore user interaction. Defaults to the root's
disabledvalue.- Type
boolean | null
nativeButton boolean true
- Name
- Description
Whether the host is a native
<button>. Setfalsewhenrendersupplies a non-button element.- Type
boolean- Default
true
onclick MouseEventHandler<HTMLElement> | null —
- Name
- Description
Runs before the trigger's handler. Call
event.preventDefault()to skip it.- Type
MouseEventHandler<HTMLElement> | null
render Snippet<[props: CollapsibleTriggerHostProps, state: CollapsibleTriggerState, children: Snippet | undefined]> —
- Name
- Description
Replace the default
<button>. Spreadpropsonto the host and renderchildren.- Type
Snippet<[props: CollapsibleTriggerHostProps, state: CollapsibleTriggerState, children: Snippet | undefined]>
open boolean
- Name
open- Description
Whether the panel is currently open.
- Type
boolean
disabled boolean
- Name
disabled- Description
Whether the collapsible should ignore user interaction.
- Type
boolean
transitionStatus TransitionStatus
- Name
transitionStatus- Description
Shared open/close motion phase.
- Type
TransitionStatus
data-panel-open
data-disabled
Panel
A panel with the collapsible contents. Renders a <div> element.
- Name
- Description
Allows the browser's page search to find and expand the panel. Overrides
keepMountedand useshidden="until-found".- Type
boolean- Default
false
keepMounted boolean false
- Name
- Description
Whether to keep the panel in the DOM while it is closed. Ignored when
hiddenUntilFoundis set.- Type
boolean- Default
false
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CollapsiblePanelState, children: Snippet | undefined]> —
- Name
- Description
Replace the default
<div>. Spreadpropsonto the host and renderchildren.- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: CollapsiblePanelState, children: Snippet | undefined]>
transitionStatus TransitionStatus
- Name
transitionStatus- Description
Panel motion phase. Can settle to idle before the root does.
- Type
TransitionStatus
open boolean
- Name
open- Description
Whether the panel is currently open.
- Type
boolean
disabled boolean
- Name
disabled- Description
Whether the collapsible should ignore user interaction.
- Type
boolean