collapsible
onChange called 0 time(s)
import { collapsible, lucide } from '@markless/ui';export default function CollapsibleBasic() @{ <collapsible.root class="collapsible" open> <collapsible.trigger class="trigger"> <lucide.chevronright class="trigger-icon" aria-hidden="true" /> What is a collapsible? <lucide.plus class="trigger-plus" aria-hidden="true" /> <lucide.minus class="trigger-minus" aria-hidden="true" /> </collapsible.trigger> <collapsible.content class="panel"> A button that shows and hides the content below it. The panel stays in the page while it is closed, so find-in-page can still reach this text. </collapsible.content> </collapsible.root>;}
.collapsible { width: min(31rem, 100%); border: 1px solid var(--ink); border-radius: 6px; overflow: clip; font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5;}.trigger { display: flex; gap: 0.75em; align-items: center; width: 100%; padding: 0.85em 1em; border: 0; background: transparent; color: var(--ink); font: inherit; font-family: 'Shantell Sans', system-ui, sans-serif; text-align: left; cursor: pointer;}.trigger-icon,.trigger-plus,.trigger-minus { display: inline-flex; width: 1em; height: 1em; flex: none; transition: transform 140ms ease;}.trigger[ui-open] .trigger-icon { transform: rotate(90deg);}.trigger-plus,.trigger-minus { margin-inline-start: auto;}.trigger-minus,.trigger[ui-open] .trigger-plus { display: none;}.trigger[ui-open] .trigger-minus { display: inline-flex;}.trigger[ui-open] { background: color-mix(in srgb, var(--purple) 26%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.trigger:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.trigger:focus-visible { outline: 2px solid var(--ink); outline-offset: -5px;}.trigger:disabled { cursor: not-allowed; opacity: 0.55;}.panel { color: var(--ink); font-family: 'Shantell Sans', system-ui, sans-serif;}/* Box styles wait for ui-open: a hidden="until-found" panel keeps its box for find-in-page. */.panel[ui-open] { padding: 1em; border-block-start: 1px solid var(--ink);}@media (prefers-reduced-motion: reduce) { .trigger-icon { transition: none; }}
A collapsible is one button that shows or hides one panel. Use it for a "Show more" section or one question with its answer. For a stack of sections, use accordion.
Anatomy
One trigger and one panel that shows or hides.
collapsible.trigger is a native <button>, so Tab reaches it, and Enter and Space press it. It
reports aria-expanded and points at the panel with aria-controls.
A closed panel stays in the page
Closing the panel hides it. It does not remove it. So anything inside keeps its state, such as text typed into a field.
A closed panel gets hidden="until-found". The browser's find-in-page still searches it, and a hit
opens the panel. onChange runs with true when that happens.
If you set disableUntilFound, a closed panel gets plain hidden instead, and find-in-page skips
it.
Styling
The family ships no CSS. It writes these attributes:
| Attribute | On | When |
|---|---|---|
ui-open |
root, trigger, content |
The panel is showing. |
ui-closed |
root, trigger, content |
The panel is hidden. |
ui-disabled |
root |
disabled is set. |
Props on collapsible.root
| Prop | Type | What it does |
|---|---|---|
open |
boolean |
Whether the panel starts open. The default is false. |
disabled |
boolean |
The trigger is disabled, so a press does nothing. |
disableUntilFound |
boolean |
A closed panel gets plain hidden, so find-in-page skips it. |
onChange |
(open: boolean) => void |
Called with the new value when the panel opens or closes. |
Every other prop goes on the root <div>. Your own onClick on the trigger runs after the panel
has changed.