Web · Components
Collapsible
A single collapsible section: "Advanced settings", "Show details", "Show more" on long text.
3 exports
Live example
Preview
Debug mode, verbose logging and experimental features are here. Search for "experimental" with the browser's find in page (Ctrl+F): the section opens by itself.
Code
Events
- Events appear here when you interact with the preview.
With your own button
- 2 × Coffee beans
- 1 × French press
Import
A single collapsible section: "Advanced settings", "Show details", "Show more" on long text. For multiple sections use Accordion.
- A built-in header (
title,icon,description) or your own button (trigger). - The height animation is CSS only; instant with "reduced motion".
- Closed content stays in the DOM and is hidden with
hidden="until-found": when the browser's find in page (Ctrl+F) finds text inside, the section opens automatically. - "Show more" mode with
collapsedHeight: no button for short content; on close the page scrolls to keep the button on screen.
Examples
CollapsibleClassNames
interfaceClasses that can be given to the inner parts of Collapsible.
| Name | Type | Description |
|---|---|---|
trigger? | string | Built-in header button. |
content? | string | Area wrapping the content. |
toggle? | string | "Show more" button (with collapsedHeight). |
CollapsibleProps
interfaceProps of the Collapsible component.
Extends: Omit<ComponentProps<"div">, "title" | "children">
| Name | Type | Default | Description |
|---|---|---|---|
children? | ReactNode | Content that opens and closes. | |
title? | ReactNode | Text of the built-in header button. Not used when trigger is given. | |
description? | ReactNode | Small description below the title. | |
icon? | IconProp | Icon at the start of the title: a name or an element. | |
trigger? | ReactElement | Your own toggle button instead of the built-in header (e.g. <Button variant="ghost">). A click toggles it; aria-expanded and aria-controls are added automatically. | |
open? | boolean | Open in controlled use? | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
disabled? | boolean | Can't be toggled. | |
collapsedHeight? | number | "Show more" mode: while closed this much of the content (pixels) is visible, ending with a fading bottom edge; the button below opens all of it. If the content is shorter than this height the button never appears. For long descriptions, reviews and product details. | |
showMoreLabel? | ReactNode | the {@link UIProvider} text | Text of the "Show more" button. |
showLessLabel? | ReactNode | the {@link UIProvider} text | Text of the "Show less" button. |
classNames? | CollapsibleClassNames | Classes added to the inner parts. | |
effect? | EffectProp | Effect or effects of the header row (or the "Show more" button) (e.g. "ripple", "border"). Defaults to UIProvider appearance.defaults.collapsible.effect. See BuiltinEffect. |