Collapsible
One region whose content shows or hides, behind a header the reader operates.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';export default function CollapsibleBasic() { return ( <Collapsible defaultOpen> <CollapsibleHeader> <CollapsibleTrigger>Delivery address</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> Northwind Traders, 402 Maple Street, Seattle, WA 98101. The dock entrance is on the east side. </CollapsiblePanel> </Collapsible> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Collapsible, CollapsibleActions, CollapsibleDefaultsProvider, CollapsibleHeader, CollapsibleMore, CollapsiblePanel, CollapsibleTrigger } from '@slotted/react';Header and panel
A collapsible is a header and the panel it controls. The trigger is a button inside the header, so Enter and Space toggle the panel and focus stays on the trigger. Every trigger, every control in the actions slot and every control inside an open panel is in the page tab sequence: nothing writes tabindex. A closed panel is out of the tab sequence and out of the accessibility tree. The trigger carries aria-expanded and aria-controls, and the panel carries aria-labelledby.
The panel opens without being measured: its height transitions between 0fr and 1fr, so the content sets it at every frame. In React, defaultOpen sets the starting state. In Angular, the open input does, and it is also the two-way binding described under Controlled.
Variants
variant sets the chrome. plain draws none, ruled draws a hairline above the header so a stack of collapsibles reads as one list, and framed draws a card. The three share one geometry, so changing the variant moves nothing.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleVariant() { return ( <Stack gap={4}> <Collapsible defaultOpen variant="plain"> <CollapsibleHeader> <CollapsibleTrigger>Payment terms</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Net 30 from the invoice date.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Shipping terms</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>FOB origin. Freight is billed at cost.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Return terms</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Thirty calendar days, unopened pallets only.</CollapsiblePanel> </Collapsible> </Stack> );}Sizes
size sets the header at one step: sm for dense panels, md for most pages, lg for sparse ones. The title follows the type scale, and the height, padding, gap and indicator follow the control scales, so a dense page is tighter rather than smaller.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleSizes() { return ( <Stack gap={4}> <Collapsible defaultOpen size="sm" variant="framed"> <CollapsibleHeader> <CollapsibleTrigger description="3 of 12 items">Inbound shipments</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Next arrival: pallet PL-4410 at 14:20.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen size="md" variant="framed"> <CollapsibleHeader> <CollapsibleTrigger description="8 of 20 items">Outbound shipments</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Next pickup: UPS Ground at 16:30.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen size="lg" variant="framed"> <CollapsibleHeader> <CollapsibleTrigger description="5 of 9 zones">Cycle counts</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Zone C closes at 17:00.</CollapsiblePanel> </Collapsible> </Stack> );}Indicator and placement
indicator picks the mark: a chevron that turns between down and up, a plus-minus that swaps one bar for the pair, or none for a header whose state aria-expanded and the panel already tell. togglePlacement="start" puts the mark before the title and indents the panel content to line up with the title. The default, end, puts the mark after the words.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleIndicator() { return ( <Stack gap={4}> <Collapsible defaultOpen indicator="chevron" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Carrier contracts</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Three active contracts renew on January 1.</CollapsiblePanel> </Collapsible> <Collapsible indicator="chevron" togglePlacement="start" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Customs documents</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Commercial invoice and packing list.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen indicator="plus-minus" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Supplier invoices</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Seven invoices are due this week.</CollapsiblePanel> </Collapsible> <Collapsible indicator="plus-minus" togglePlacement="start" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Purchase orders</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Twelve orders await approval.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen indicator="none" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Dock schedule</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Door 4 is reserved from 08:00 to 10:00.</CollapsiblePanel> </Collapsible> </Stack> );}Headings and landmarks
level wraps the trigger in a heading from 1 to 6, so a screen reader’s heading list holds the collapsible at its depth. The default, none, writes no heading semantics, for a collapsible that belongs to no outline. In React, level renders the element. In Angular, the header is the element the template writes: a native h1 to h6 is left as it is, and any other element receives role="heading" and the resolved aria-level. A collapsible nests inside another one’s panel without the outer one opening it.
region makes the panel a region landmark, named by its trigger. It is off by default because a landmark per panel fills the landmark list: use it for the two or three collapsibles a reader navigates to directly.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleHeading() { return ( <Collapsible defaultOpen level="2" region variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Return policy</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> <Stack gap={2}> <Collapsible defaultOpen level="3" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>Domestic orders</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Thirty calendar days from delivery.</CollapsiblePanel> </Collapsible> <Collapsible level="3" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger>International orders</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Sixty days. The buyer pays return freight.</CollapsiblePanel> </Collapsible> </Stack> </CollapsiblePanel> </Collapsible> );}Title, summary and description
description is a second line under the title. summary stands at the end of the title line, before the indicator, on one line cut with an ellipsis. Both sit inside the trigger, so a screen reader announces them with the title. truncate clips a title to one line, with the whole string still in the DOM. Without it, a long title grows the row instead of pushing the indicator off the line.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleDetails() { return ( <Stack gap={2}> <Collapsible variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger description="14 orders, $182,400.00"> Open purchase orders </CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>PO-2201 to PO-2214, all due before March 15.</CollapsiblePanel> </Collapsible> <Collapsible variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger summary="4 scheduled">Carrier pickups</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>UPS 16:30, FedEx 17:00, USPS 18:00, DHL 18:30.</CollapsiblePanel> </Collapsible> <Collapsible truncate variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger summary="Updated Mar 4"> Return conditions for international orders shipped from the Reno warehouse </CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Sixty days. The buyer pays return freight.</CollapsiblePanel> </Collapsible> </Stack> );}Actions beside the header
CollapsibleActions in React and slCollapsibleActions in Angular hold controls that stay visible whether the panel is open or closed. The slot is a sibling of the header, not a child, because the pattern requires the trigger to be the only element inside the heading and a control cannot sit inside a button. Put a toolbar in it so the actions take one tab stop. Below 22rem the slot moves to a row of its own.
import { Button } from '@slotted/react/button';import { Collapsible, CollapsibleActions, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Toolbar } from '@slotted/react/toolbar';export default function CollapsibleActionsExample() { return ( <Collapsible defaultOpen variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Free shipping rule</CollapsibleTrigger> </CollapsibleHeader> <CollapsibleActions> <Toolbar aria-label="Free shipping rule actions" size="sm"> <Button size="sm" variant="ghost"> Edit </Button> <Button size="sm" variant="ghost"> Duplicate </Button> </Toolbar> </CollapsibleActions> <CollapsiblePanel> Free shipping over $250.00 on orders to the contiguous states. </CollapsiblePanel> </Collapsible> );}When the content exists
mount decides when the panel’s content is built. The panel element always exists, so aria-controls never names an element that is gone.
activebuilds the content on opening and drops it on closing, so closing is instant and the content loses its state.lazybuilds it on the first opening and keeps it.eager, the default, builds it from the start, which is what lets the panel transition closed.until-foundbuilds it from the start and writeshidden="until-found"while closed, so the browser’s find-in-page opens the panel when the text matches.
Type in each note, close the panel and open it again: the first note is cleared and the other two are kept. To try until-found, search the page for “Anna Rivers” with the browser’s find command. In Angular, active and lazy need the content inside an ng-template marked slCollapsibleContent, because projected content is built whether or not it is inserted.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import type { CollapsibleMount } from '@slotted/react/collapsible';import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';const NOTES: { mount: CollapsibleMount; title: string }[] = [ { mount: 'active', title: 'Dock notes' }, { mount: 'lazy', title: 'Carrier notes' }, { mount: 'eager', title: 'Receiving notes' },];export default function CollapsibleMountExample() { return ( <Stack gap={2}> {NOTES.map((note) => ( <Collapsible key={note.mount} mount={note.mount} variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger description={note.mount}>{note.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> <Field> <FieldLabel>Note</FieldLabel> <TextField placeholder="Type, close and reopen" /> </Field> </CollapsiblePanel> </Collapsible> ))} <Collapsible mount="until-found" variant="ruled"> <CollapsibleHeader> <CollapsibleTrigger description="until-found">Delivery history</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> Delivered on March 2 by Anna Rivers to the Reno warehouse. </CollapsiblePanel> </Collapsible> </Stack> );}Peek
peek takes a length. A closed panel then keeps that block size of its content in view under a fade, and stays inert. It animates to its full size on opening. CollapsibleMore in React and slCollapsibleMore in Angular draw the control that opens the panel, after the panel, over the fade. The control exists only while the panel is closed and peek is set. A peeking panel always mounts its content, whatever mount says.
08:05 Pallet PL-4401 received at door 2, 24 cartons, no damage.
08:40 Pallet PL-4402 received at door 2, 18 cartons, one crushed corner.
09:15 Pallet PL-4403 received at door 4, 30 cartons, no damage.
10:02 Pallet PL-4404 held for inspection, seal broken on arrival.
10:48 Pallet PL-4405 received at door 4, 12 cartons, no damage.
11:30 Pallet PL-4406 received at door 1, 40 cartons, no damage.
import { Collapsible, CollapsibleHeader, CollapsibleMore, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';export default function CollapsiblePeek() { return ( <Collapsible peek="6rem" variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Receiving log</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> <p>08:05 Pallet PL-4401 received at door 2, 24 cartons, no damage.</p> <p>08:40 Pallet PL-4402 received at door 2, 18 cartons, one crushed corner.</p> <p>09:15 Pallet PL-4403 received at door 4, 30 cartons, no damage.</p> <p>10:02 Pallet PL-4404 held for inspection, seal broken on arrival.</p> <p>10:48 Pallet PL-4405 received at door 4, 12 cartons, no damage.</p> <p>11:30 Pallet PL-4406 received at door 1, 40 cartons, no damage.</p> </CollapsiblePanel> <CollapsibleMore>Show full log</CollapsibleMore> </Collapsible> );}States
disabled writes the native disabled attribute on the trigger, so the header answers neither the pointer nor the keyboard. The panel keeps its current state. loading marks the panel with aria-busy and keeps it at least one line tall. The content that stands in for the missing data is the consumer’s: here, a text skeleton in the shape of the history it will hold.
import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { SkeletonText } from '@slotted/react/skeleton';import { Stack } from '@slotted/react/stack';export default function CollapsibleStates() { return ( <Stack gap={4}> <Collapsible defaultOpen disabled variant="framed"> <CollapsibleHeader> <CollapsibleTrigger description="Read only">Archived carriers</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Contracts with these carriers closed on December 31.</CollapsiblePanel> </Collapsible> <Collapsible defaultOpen loading variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Delivery history</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> <SkeletonText lines={3} /> </CollapsiblePanel> </Collapsible> </Stack> );}Controlled
Pass open to own the state. In React, onOpenChange receives the new value and a request with the reason (pointer, keyboard, select or programmatic), and the panel moves only when open changes. In Angular, [(open)] keeps a signal in step with the panel, and openChangeRequest emits the same request before the panel moves. The buttons above the panel set the state without a request, so the reason reads the last request from the trigger.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function CollapsibleControlled() { const [open, setOpen] = useState(false); const [reason, setReason] = useState('none yet'); return ( <Stack gap={3}> <Inline gap={2}> <Button onClick={() => setOpen(true)} size="sm" variant="outline"> Show pick list </Button> <Button onClick={() => setOpen(false)} size="sm" variant="outline"> Hide pick list </Button> </Inline> <Collapsible onOpenChange={(next, request) => { setOpen(next); setReason(request.reason); }} open={open} variant="framed" > <CollapsibleHeader> <CollapsibleTrigger>Pick list for wave 12</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>42 lines across 9 orders, starting at aisle B.</CollapsiblePanel> </Collapsible> <Text size="sm" tone="muted"> Reason of the last request from the trigger: {reason}. </Text> </Stack> );}Defaults for an application
CollapsibleDefaultsProvider in React and provideCollapsibleDefaults in Angular set size, variant, indicator, togglePlacement, level, mount, peek and truncate once for everything under them. A collapsible that states a value of its own keeps it, as the last one does here.
import { Collapsible, CollapsibleDefaultsProvider, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';export default function CollapsibleDefaults() { return ( <CollapsibleDefaultsProvider indicator="plus-minus" size="sm" togglePlacement="start" variant="ruled" > <Stack gap={2}> <Collapsible defaultOpen> <CollapsibleHeader> <CollapsibleTrigger>Receiving dock</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Six pallets are waiting for putaway.</CollapsiblePanel> </Collapsible> <Collapsible> <CollapsibleHeader> <CollapsibleTrigger>Cold storage</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Temperature held at 36 degrees F.</CollapsiblePanel> </Collapsible> <Collapsible indicator="chevron" togglePlacement="end" variant="framed"> <CollapsibleHeader> <CollapsibleTrigger>Returns</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>Fourteen units are waiting for inspection.</CollapsiblePanel> </Collapsible> </Stack> </CollapsibleDefaultsProvider> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Enter | toggles the panel | stays on the trigger |
| Space | toggles the panel | stays on the trigger |
| Tab | moves to the next focusable element; the trigger, everything in the actions slot and everything inside an open panel are all in the page tab sequence | the next focusable element |
| Shift+Tab | moves to the previous focusable element, under the same rule | the previous focusable element |
- The pattern is the WAI-ARIA APG’s Disclosure (w3.org/WAI/ARIA/apg/patterns/disclosure/), and inside an Accordion it answers the Accordion pattern as well. Its whole keyboard table is the platform’s: the trigger is a button, so Enter and Space toggle without Collapsible binding a key, and Tab reaches it like any other control — the pattern requires every focusable element in an accordion to be in the page tab sequence, which is why nothing here writes tabindex.
- The trigger carries aria-expanded and aria-controls; the panel carries aria-labelledby pointing back. Both identifiers come from useId, so a server response and the first client render agree. The panel’s box is never removed — mount drops its content, not the box — because aria-controls naming an element that is not there is a reference a screen reader has to make sense of.
- A closed panel is out of the tab sequence and out of the accessibility tree twice over: the stylesheet with content-visibility, and the binding with inert, so a browser without the property still cannot put focus inside it. Under mount="until-found" neither applies: hidden="until-found" is what lets the browser’s page search reach the text and open the panel, and beforematch is what tells Collapsible to open.
- The heading is real. level renders h1 to h6 and the trigger is its only element, which is what the pattern requires; an accordion sets the level once for a whole set. level="none" writes no heading semantics at all, for a disclosure that belongs to no outline.
- aria-disabled appears on the trigger only when an Accordion refuses to let this panel close. That is the pattern’s own instruction for a set that requires one panel to stay open, and it leaves the control focusable and announced rather than removing it from the reader’s path.
- The trigger is a button and the panel a div, rather than details and summary. What that costs is written down: a page with JavaScript disabled cannot open a panel. What it buys is the accordion pattern — a summary cannot be wrapped in a heading — a value the consumer can own, a request that carries a reason, and a panel that animates without interpolate-size.
- The mark is never the only thing that says the state: aria-expanded says it to a reader, and the indicator turns rather than changing color, so the high-contrast scheme and forced colors both keep it.
API
Collapsible
Props
openboolean- Present means the consumer owns the state, for the life of the component. Inside an Accordion the set owns it instead, and an explicit open still wins over both.
defaultOpenboolean- The value an uncontrolled disclosure starts from, read once. A later change to it does not silently become new state.
size'sm' | 'md' | 'lg'Defaultmd- On Collapsible, Accordion, CollapsibleDefaultsProviderThe step the header sits at. The title comes from the type scale and everything geometric from the control scales, so a density changes the rhythm rather than the reading size.
variant'plain' | 'ruled' | 'framed'Defaultplain- On Collapsible, CollapsibleDefaultsProviderplain paints no chrome, ruled draws a hairline above the header so a stack reads as one list, and framed is its own card. An Accordion hands its items the one its own variant maps onto.
indicator'chevron' | 'plus-minus' | 'none'Defaultchevron- On Collapsible, Accordion, CollapsibleDefaultsProviderThe mark, drawn from a glyph token. The chevron turns between down and up rather than pointing along the inline axis, so nothing is mirrored for a right-to-left document.
togglePlacement'end' | 'start'Defaultend- On Collapsible, Accordion, CollapsibleDefaultsProviderWhich side of the words the mark stands on. With it at the start the panel’s content is indented to line up with the title rather than with the mark.
level'none' | '1' | '2' | '3' | '4' | '5' | '6'Defaultnone- On Collapsible, CollapsibleDefaultsProviderThe heading element the trigger is wrapped in. none renders a div and writes no heading semantics; an Accordion sets it for a whole set through headingLevel.
mount'active' | 'lazy' | 'eager' | 'until-found'Defaulteager- On Collapsible, Accordion, CollapsibleDefaultsProviderWhen the panel’s content exists. The box always does, so aria-controls never names an element that is gone. until-found writes hidden="until-found" and answers beforematch by opening.
peekstring- On Collapsible, CollapsibleDefaultsProviderA length (9rem): a closed panel keeps that block size of its content in view under a fade, stays inert, and animates to its full size with the same durations; forced colors drop the fade and keep the clip. The panel carries data-state="peek", and mount is forced to eager.
truncatebooleanDefaultfalse- On Collapsible, Accordion, CollapsibleDefaultsProviderClips the title to one line instead of letting the row grow. The whole string stays in the DOM, which holds for every component.
regionbooleanDefaultfalse- Makes the panel a region landmark. Off by default, because the pattern’s own example warns that a landmark per panel fills the landmark list.
disabledbooleanDefaultfalse- Reaches the trigger as the native attribute, which is also what stops the press. Unstated rather than false, so the disclosure defers to the Accordion around it.
loadingbooleanDefaultfalse- The panel keeps a line’s height and carries aria-busy; what stands in for the content is Skeleton, composed by the consumer.
valuestringDefault from useId- What this disclosure is called inside an Accordion. It is identity rather than state, and it reaches the DOM as data-value.
summaryReactNode- On CollapsibleTriggerWhat the disclosure holds, at the end of the title line and before the mark, cut with an ellipsis; inside the trigger and therefore inside its accessible name.
descriptionReactNode- On CollapsibleTriggerA second line under the title, inside the trigger and therefore inside its accessible name.
Events
| Name | Payload | When |
|---|---|---|
onOpenChange | (open: boolean, request: ChangeRequest<boolean>) | Before the panel moves. The request carries the new value, the value it replaces, the reason (pointer, keyboard, select or programmatic), the originating event, and cancel(), which refuses the move before anything commits. Inside an Accordion it still fires, so a consumer may watch one panel without unpacking the set’s array. |
onClick, onFocus, onKeyDown, on the trigger | the element’s own events | Whenever the button fires them. Collapsible composes with a consumer’s handler rather than replacing it: the consumer’s runs first, and preventDefault() in onClick refuses the toggle as well. |
Composition
render(props) => ReactNode- On Collapsible, CollapsibleHeader, CollapsibleTrigger, CollapsibleActions, CollapsiblePanelSubstitutes any of the five roots and hands it every attribute — a disclosure can be a section, a panel an article. The heading may become another element, but the trigger has to stay its only child.
refRef<HTMLElement>- On every partReaches the element itself, so focus() and click() are the platform’s and no imperative handle is invented for what it already ships.
useCollapsible()() => CollapsibleContextValue- On inside CollapsibleWhat the parts read: the open state, the identifiers, the mount strategy, whether the group holds this one open, and toggle(next, reason). It throws outside Collapsible rather than rendering a control that does nothing.
CollapsibleDefaultsProvider{ size, variant, indicator, togglePlacement, level, mount, peek, truncate }- On a subtreeThe decisions an application takes once: size, variant, indicator, togglePlacement, level, mount, peek and truncate. An Accordion sits between it and the item, and a disclosure that states any of them itself still wins.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, or the element render returns | Yes | The root. A two-column, two-row grid carrying data-ui="collapsible", data-size, data-variant, data-indicator, data-toggle-placement, data-mount, data-truncate, data-open, data-disabled, data-loading, data-peek and data-value. It is also its own container, so the header reflows on its own inline size rather than the viewport’s. |
header | h1 to h6, or a div at level="none" | Yes | The heading. level decides the element, and the accordion sets it for a whole set at once. Its only child is the trigger: the pattern requires the button to be the only element inside the heading. |
trigger | button | Yes | The control. Holds aria-expanded, aria-controls, the identifier, and every native prop and ref the consumer wrote. Enter and Space are the platform’s, so Collapsible binds no key of its own. |
indicator | span | No | The mark, drawn as a mask from a glyph token. A chevron turns between down and up; plus-minus swaps one bar for the pair. indicator="none" draws nothing at all. |
label | span | Yes | The title. A box of its own, so text-overflow has something to clip under truncate and so a title in another script reads its own way without reordering the row around it. |
summary | span | No | What the disclosure holds, at the end of the title line and before the mark: one line, cut with an ellipsis, in the description ink. It is inside the trigger, so it is part of the accessible name. |
description | span | No | A second line under the title. It is inside the trigger, so it is part of the accessible name — “Delivery, 3 of 12 items” is what a reader hears. |
actions | div, or the element render returns | No | The always-visible controls beside the header, on its own row and outside the button. What belongs in it is a Toolbar. Below 22rem it takes a row of its own. |
panel | div, optionally role="region" | Yes | The box the trigger controls: aria-labelledby its trigger, inert while closed, and hidden="until-found" under that mount. The box always exists, so aria-controls never names an element that is gone. |
content | div | Yes | What the panel’s grid track clips. Its content-visibility is what takes closed content out of the tab sequence, out of the accessibility tree and out of the browser’s page search. mount decides whether it is built at all. |
more | button | No | The control that opens a peeking panel, placed after the panel and drawn over its fade. It exists only while the panel is closed and peek is set. It opens the panel and names it through aria-controls, as the trigger does. render replaces it, with a Button for example. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every collapsible inside it.
Collapsible tokens
| Token | Default |
|---|---|
--slotted-collapsible-active-background | var(--slotted-tone-secondary-subtle-active) |
--slotted-collapsible-background | transparent |
--slotted-collapsible-border-color | var(--slotted-collapsible-rule-color, var(--slotted-border-subtle, ButtonBorder)) |
--slotted-collapsible-color | var(--slotted-text, CanvasText) |
--slotted-collapsible-description-color | var(--slotted-text-muted, GrayText) |
--slotted-collapsible-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-collapsible-hover-color | var(--slotted-text, CanvasText) |
--slotted-collapsible-indicator-color | currentColor |
--slotted-collapsible-more-overlap | 1.5rem |
--slotted-collapsible-padding-inline | var(--_padding-inline) |
--slotted-collapsible-panel-color | var(--slotted-text, CanvasText) |
--slotted-collapsible-panel-padding-block-start | var(--_padding-block) |
--slotted-collapsible-peek-fade | 3rem |
--slotted-collapsible-radius | var(--slotted-control-radius, 4px) |
--slotted-collapsible-rule-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-collapsible-shadow | none |
--slotted-collapsible-surface | var(--slotted-surface-raised, Canvas) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-gap-lg | comfortable 8px · compact 6px · dense 6px |
--slotted-control-gap-md | comfortable 8px · compact 6px · dense 4px |
--slotted-control-gap-sm | comfortable 6px · compact 4px · dense 4px |
--slotted-control-height-lg | comfortable 38px · compact 32px · dense 30px |
--slotted-control-height-md | comfortable 34px · compact 28px · dense 26px |
--slotted-control-height-sm | comfortable 30px · compact 26px · dense 24px |
--slotted-control-icon-size-lg | comfortable 18px · compact 16px · dense 14px |
--slotted-control-icon-size-md | comfortable 16px · compact 14px · dense 13px |
--slotted-control-icon-size-sm | comfortable 14px · compact 13px · dense 12px |
--slotted-control-letter-spacing | 0 |
--slotted-control-padding-inline-lg | comfortable 16px · compact 12px · dense 10px |
--slotted-control-padding-inline-md | comfortable 13px · compact 10px · dense 8px |
--slotted-control-padding-inline-sm | comfortable 10px · compact 8px · dense 6px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-duration-medium | 200ms |
--slotted-duration-short | 120ms |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-size-lg | 1rem |
--slotted-font-size-md | 0.875rem |
--slotted-font-size-sm | 0.8125rem |
--slotted-font-size-xs | 0.75rem |
--slotted-font-weight-medium | 500 |
--slotted-font-weight-regular | 400 |
--slotted-line-height-md | 1.5 |
--slotted-radius-md | 6px |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |