Search documentation

Find a component or a docs page

Collapsible

An interactive component which expands/collapses a panel.

Usage

Example

CollapsibleTrigger is the button itself. Pass Button options (variant:, size:, icon:) to style it as a Button.

Open

open: sets the initial state. The server renders it, so the panel shows the right state before any JavaScript runs.

Rotating icon

The trigger gets data-panel-open while open, and the root and content get data-open / data-closed, so you can style by state.

Disabled

Animated

The panel exposes --collapsible-panel-height and gets data-starting-style while opening and data-ending-style while closing; it is hidden once its animation ends.

Find in page

With hidden_until_found: true the browser's find in page can reach the hidden text and opens the panel. Try searching for “rubyists”.

Events

Each toggle dispatches ruby-ui--collapsible:change with detail: {open} before the state changes. Call preventDefault() to keep the current state. To open or close from your own code, set the data-ruby-ui--collapsible-open-value attribute on the root.

Installation

Components

ComponentBuilt usingSource
CollapsiblePhlex
CollapsibleContentPhlex
CollapsibleDocsPhlex
CollapsibleTriggerPhlex
CollapsibleControllerStimulus JS