Accordion
A set of sections that expand and collapse, with one or several open at a time and a keyboard path between headers.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' }, { value: 'returns', title: 'Returns', body: 'Accepted within 30 days of delivery, with the original packing slip.', },];export default function AccordionBasic() { return ( <Accordion defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> );}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 { Accordion, AccordionDefaultsProvider, Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger } from '@slotted/react';One panel at a time
By default the set holds one open panel. Opening a section closes the one that was open, and that panel is told the reason was select. Each section is a Collapsible whose value names it in the set’s array of open values. Pass defaultValue in React, or an initial value in Angular, to choose what starts open.
Several panels at once
multiple lets any number of panels stay open, so a reader can compare sections without closing one to read another. Use it when the sections are independent, as the tasks of a shift are.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';const TASKS = [ { value: 'receiving', title: 'Receiving', body: '14 pallets arrive today between 08:00 and 15:00.', }, { value: 'putaway', title: 'Putaway', body: '6 pallets wait in dock 3 for a bin assignment.' }, { value: 'counts', title: 'Cycle counts', body: 'Aisles 12 to 15 are due this week.' }, { value: 'dispatch', title: 'Dispatch', body: 'The 16:30 carrier pickup holds 38 parcels.' },];export default function AccordionMultiple() { return ( <Accordion multiple defaultValue={['receiving', 'putaway']}> {TASKS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> );}A set that never empties
requireOpen keeps one panel open. The open header cannot be pressed to close it, and it carries aria-disabled="true", which the pattern asks for an accordion that does not permit its panel to be collapsed. The header stays focusable and announced. Open another section and the new one takes its place.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';const ACCOUNT = [ { value: 'summary', title: 'Summary', body: 'Harbor & Pine Supply Co., customer since 2019.' }, { value: 'contacts', title: 'Contacts', body: 'Mira Alvarez, purchasing, and Tomas Berg, accounts payable.', }, { value: 'terms', title: 'Payment terms', body: 'Net 30, with a 2% discount when paid within 10 days.', },];export default function AccordionRequireOpen() { return ( <Accordion requireOpen defaultValue={['summary']}> {ACCOUNT.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> );}Variants
variant sets how the set is drawn. plain paints nothing, ruled puts one hairline at each seam and closes the stack at the bottom, framed wraps the ruled set in one frame, and separated gives each section a card of its own. The set hands each item the variant it needs, so the items never select into the set’s styles.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },];const VARIANTS = ['plain', 'ruled', 'framed', 'separated'] as const;export default function AccordionVariants() { return ( <Stack gap={6}> {VARIANTS.map((value) => ( <Stack key={value} gap={2}> <Text size="sm" tone="muted"> variant="{value}" </Text> <Accordion variant={value} defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> ))} </Stack> );}Sizes
size sets the type of every title and the rhythm of every row to one step: sm for dense panels, md for most pages, lg for sparse pages. Under separated, the gap between cards moves with it.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },];const SIZES = ['sm', 'md', 'lg'] as const;export default function AccordionSizes() { return ( <Stack gap={6}> {SIZES.map((value) => ( <Stack key={value} gap={2}> <Text size="sm" tone="muted"> size="{value}" </Text> <Accordion size={value} defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> ))} </Stack> );}Indicator and placement
indicator picks the mark on each header: chevron, which turns when the panel opens, plus-minus, which swaps between two glyphs, or none, which leaves the title alone. togglePlacement="start" moves the mark before the title; the default, end, puts it after.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },];export default function AccordionIndicator() { return ( <Stack gap={6}> <Stack gap={2}> <Text size="sm" tone="muted"> indicator="chevron" </Text> <Accordion indicator="chevron" defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> <Stack gap={2}> <Text size="sm" tone="muted"> indicator="plus-minus" togglePlacement="start" </Text> <Accordion indicator="plus-minus" togglePlacement="start" defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> <Stack gap={2}> <Text size="sm" tone="muted"> indicator="none" </Text> <Accordion indicator="none" defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> </Stack> );}Heading level
Each header is a heading, so a screen reader user can move through the sections as an outline. In React, headingLevel renders each header as that heading element, and none renders a plain div; the default is 3. In Angular, a native heading element is left as it is, so level 2 is an h2 in the template; any other element receives role="heading" and the aria-level the set resolves, and none removes both.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },];export default function AccordionHeadings() { return ( <Stack gap={6}> <Stack gap={2}> <Text size="sm" tone="muted"> headingLevel="2" </Text> <Accordion headingLevel="2" defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> <Stack gap={2}> <Text size="sm" tone="muted"> headingLevel="none" </Text> <Accordion headingLevel="none" defaultValue={['delivery']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> </Stack> );}When panels are built
mount decides when a panel’s content exists. eager, the default, renders every panel and makes the closed ones inert. lazy renders a panel on its first open and keeps it. active renders only the open panel and discards the content on close. until-found keeps the closed panel hidden but searchable: the browser’s find-in-page opens it when the text matches. Type a note, close the section and open it again: active loses the text, the others keep it.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';const MOUNTS = ['active', 'lazy', 'eager', 'until-found'] as const;export default function AccordionMount() { return ( <Stack gap={6}> {MOUNTS.map((mount) => ( <Stack key={mount} gap={2}> <Text size="sm" tone="muted"> mount="{mount}" </Text> <Accordion mount={mount}> <Collapsible value="note"> <CollapsibleHeader> <CollapsibleTrigger>Carrier note</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel> <Field> <FieldLabel>Note for the carrier</FieldLabel> <TextField /> </Field> </CollapsiblePanel> </Collapsible> </Accordion> </Stack> ))} </Stack> );}States
disabled on the set reaches every trigger as the native attribute and takes each out of the tab order. disabled on one Collapsible leaves the rest of the set live.
import { Accordion } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },];const REVIEW = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' }, { value: 'hold', title: 'Credit hold', body: 'Released by finance on October 1.', disabled: true, },];export default function AccordionStates() { return ( <Stack gap={6}> <Stack gap={2}> <Text size="sm" tone="muted"> disabled </Text> <Accordion disabled defaultValue={['payment']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> <Stack gap={2}> <Text size="sm" tone="muted"> disabled on one item </Text> <Accordion defaultValue={['payment']}> {REVIEW.map((section) => ( <Collapsible key={section.value} value={section.value} disabled={section.disabled}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> </Stack> );}Controlled
Pass value to own the set of open panels. In React, onValueChange receives the new array and a request that carries the reason (pointer, keyboard, select or programmatic) and a cancel() that refuses the move. In Angular, [(value)] writes the array back and valueChangeRequest emits the same request. A change made by the application’s own code, such as the button here, emits no request.
import { useState } from 'react';import { Accordion } from '@slotted/react/accordion';import type { AccordionChangeRequest } from '@slotted/react/accordion';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';const SECTIONS = [ { value: 'delivery', title: 'Delivery', body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.', }, { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' }, { value: 'returns', title: 'Returns', body: 'Accepted within 30 days of delivery, with the original packing slip.', },];export default function AccordionControlled() { const [open, setOpen] = useState<readonly string[]>(['delivery']); const [reason, setReason] = useState('none'); function handleValueChange(next: readonly string[], request: AccordionChangeRequest) { setOpen(next); setReason(request.reason); } return ( <Stack gap={4}> <Inline gap={3} align="center" justify="between"> <Text size="sm" tone="muted"> Open: {open.join(', ') || 'none'}. Last change by the reader: {reason}. </Text> <Button size="sm" variant="outline" onClick={() => setOpen(['payment'])}> Show payment </Button> </Inline> <Accordion value={open} onValueChange={handleValueChange}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> );}Open all and close all
An array cannot express “every section” when the set owns it, so the set exposes openAll() and closeAll(). In React they sit on the object passed to handle; in Angular, exportAs reaches the set from the template. Both carry the reason programmatic. openAll skips a disabled section and opens only the first when multiple is off, and closeAll leaves one open when requireOpen is on.
import { useRef } from 'react';import { Accordion } from '@slotted/react/accordion';import type { AccordionHandle } from '@slotted/react/accordion';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';const TASKS = [ { value: 'receiving', title: 'Receiving', body: '14 pallets arrive today between 08:00 and 15:00.', }, { value: 'putaway', title: 'Putaway', body: '6 pallets wait in dock 3 for a bin assignment.' }, { value: 'counts', title: 'Cycle counts', body: 'Aisles 12 to 15 are due this week.' }, { value: 'archive', title: 'Archived pallets', body: 'Moved to cold storage on September 30.', disabled: true, },];export default function AccordionImperative() { const set = useRef<AccordionHandle>(null); return ( <Stack gap={4}> <Inline gap={2}> <Button size="sm" variant="outline" onClick={() => set.current?.openAll()}> Open all </Button> <Button size="sm" variant="outline" onClick={() => set.current?.closeAll()}> Close all </Button> </Inline> <Accordion handle={set} multiple> {TASKS.map((task) => ( <Collapsible key={task.value} value={task.value} disabled={task.disabled}> <CollapsibleHeader> <CollapsibleTrigger>{task.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{task.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> );}Defaults for an application
AccordionDefaultsProvider in React and provideAccordionDefaults in Angular set the ten decisions an application takes once: multiple, requireOpen, loop, size, variant, indicator, togglePlacement, headingLevel, mount and truncate. A set that states one of them keeps its own value. Here truncate clips each long title to one line, and the second set overrides the variant.
import { Accordion, AccordionDefaultsProvider } from '@slotted/react/accordion';import { Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger,} from '@slotted/react/collapsible';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SECTIONS = [ { value: 'po', title: 'Purchase order PO-44821 from Harbor & Pine Supply Co. awaiting approval', body: 'Requested by Mira Alvarez for $12,480.00.', }, { value: 'rma', title: 'Return authorization RMA-3107 for 24 damaged cartons', body: 'Credit of $1,036.80 issues after inspection.', },];export default function AccordionDefaults() { return ( <AccordionDefaultsProvider variant="separated" indicator="plus-minus" truncate> <Stack gap={6}> <Stack gap={2}> <Text size="sm" tone="muted"> From the defaults </Text> <Accordion defaultValue={['po']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> <Stack gap={2}> <Text size="sm" tone="muted"> variant="plain" on the set </Text> <Accordion variant="plain" defaultValue={['po']}> {SECTIONS.map((section) => ( <Collapsible key={section.value} value={section.value}> <CollapsibleHeader> <CollapsibleTrigger>{section.title}</CollapsibleTrigger> </CollapsibleHeader> <CollapsiblePanel>{section.body}</CollapsiblePanel> </Collapsible> ))} </Accordion> </Stack> </Stack> </AccordionDefaultsProvider> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Enter | toggles the panel of the focused header; with `multiple` off, the panel that was open closes with the reason `select` | stays on the trigger |
| Space | the same as Enter | stays on the trigger |
| Tab | moves to the next focusable element; every focusable element in the accordion is 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 |
| ArrowDown | moves to the next header and wraps at the end when loop is on; opens nothing | the header moved to |
| ArrowUp | moves to the previous header and wraps at the start when loop is on; opens nothing | the header moved to |
| Home | moves to the first header that is not disabled | the first enabled header |
| End | moves to the last header that is not disabled | the last enabled header |
- The pattern is the WAI-ARIA APG’s Accordion (w3.org/WAI/ARIA/apg/patterns/accordion/). Its keyboard table is four keys and all four are the platform’s: Enter and Space toggle the focused header because it is a button, and Tab and Shift + Tab move through the set because every focusable element in an accordion is in the page tab sequence. Nothing here writes tabindex.
- ArrowDown, ArrowUp, Home and End are a deliberate departure, and the cost is written down. The arrows were optional guidance until w3c/aria-practices#3434 removed them, and Base UI deprecated its own loopFocus and orientation in the same change; Radix and Ark still ship them and readers have learned them. Here they are additive — they move focus between headers, open nothing, and take no header out of the tab sequence — so a reader who does not know them loses nothing.
- Each header is a real heading at the level headingLevel names, and the trigger is its only element, which is what the pattern requires. The set itself carries no role: a group of headings is already an outline a reader can navigate, and a container announced around it is one more thing to move past.
- requireOpen writes aria-disabled="true" on the one header the set will not let close. The pattern asks for exactly that, and the APG’s own example is the only surveyed implementation that ships it; the header stays focusable and announced rather than leaving the reader’s path.
- A horizontal accordion is not shipped. Radix and Ark both offer one and Base UI has deprecated its own; a horizontally stacked set of sections of which one is open is a tab list, and tabs owns it — with the marker, the scrolling list and that pattern’s own keyboard model.
- Which header has focus is read from the platform: onFocusIn on the set and event.target.dataset.value. Ark ships an output for it, and an output that repeats what the DOM already says is one more thing to keep in step.
API
Accordion
Props
valuereadonly string[]- Present means the consumer owns the set of open panels, for the life of the component. Each entry is a Collapsible’s value.
defaultValuereadonly string[]- The set an uncontrolled accordion starts from, read once. A later change to it does not silently become new state.
multiplebooleanDefaultfalse- On Accordion, AccordionDefaultsProviderWhether more than one panel may be open. With it off, opening one closes the one that was, and that panel is told the reason was select.
requireOpenbooleanDefaultfalse- On Accordion, AccordionDefaultsProviderWhether the set refuses to empty. The one open header then carries aria-disabled="true", which is what the pattern asks of an accordion that does not permit its panel to be collapsed.
loopbooleanDefaulttrue- On Accordion, AccordionDefaultsProviderWhether the arrow keys wrap past the ends of the set.
size'sm' | 'md' | 'lg'Defaultmd- On Accordion, AccordionDefaultsProviderThe step every item sits at, and the air between cards under separated.
variant'plain' | 'ruled' | 'framed' | 'separated'Defaultruled- On Accordion, AccordionDefaultsProviderHow the set is drawn. Each value maps onto the item variant the set hands over: plain to plain, ruled and framed to ruled, separated to framed. The set never selects into an item to draw it.
indicator'chevron' | 'plus-minus' | 'none'Defaultchevron- On Accordion, AccordionDefaultsProviderThe mark every header carries, handed to each item.
togglePlacement'end' | 'start'Defaultend- On Accordion, AccordionDefaultsProviderWhich side of the words that mark stands on, handed to each item.
headingLevel'none' | '1' | '2' | '3' | '4' | '5' | '6'Default3- On Accordion, AccordionDefaultsProviderThe heading element every item’s header renders as. 3 is the level the pattern’s own example uses for a set inside a section.
mount'active' | 'lazy' | 'eager' | 'until-found'Defaulteager- On Accordion, AccordionDefaultsProviderWhen each panel’s content exists, handed to every item.
truncatebooleanDefaultfalse- On Accordion, AccordionDefaultsProviderClips every title to one line instead of letting the row grow.
disabledbooleanDefaultfalse- Reaches every item, and every trigger as the native attribute.
Events
| Name | Payload | When |
|---|---|---|
onValueChange | (value: readonly string[], request: ChangeRequest<readonly string[]>) | Before the set of open panels moves. The request carries the new set, the set it replaces, the reason (pointer, keyboard, select or programmatic), the originating event, and cancel(), which refuses the move before anything commits. Two sets holding the same values in any order are the same set, so no request is emitted for a move that changes nothing. |
onOpenChange, on each item | (open: boolean, request: ChangeRequest<boolean>) | Before that one panel moves, and before the set is asked. It is what lets a consumer watch one section without unpacking the array, and cancelling it stops the set from being asked at all. |
onFocusIn, onKeyDown, on the set | the element’s own events | Whenever the set fires them. Which header has focus is read from event.target.dataset.value, which is why the family ships no separate focus-change output. |
Composition
handleRef<AccordionHandle>- openAll() and closeAll(), the two moves an array cannot express while the family owns the array. They are on a handle of their own so ref keeps reaching the element, which is the rule for every other family here.
render(props) => ReactNode- Substitutes the set’s root and hands it every attribute — a set of sections can be a real section element.
refRef<HTMLElement>- Reaches the element itself, so the platform’s own methods are the platform’s.
useAccordion()() => AccordionContextValue | undefined- On inside AccordionWhat each item reads: the axes the set hands over, whether a value is open, whether it is held open, and toggle(value, reason). It is undefined outside a set rather than a throw, because a Collapsible standing alone is a complete component.
AccordionDefaultsProvider{ multiple, requireOpen, loop, size, variant, indicator, togglePlacement, headingLevel, mount, truncate }- On a subtreeThe ten decisions an application takes once. A set that states any of them itself still wins.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, or the element render returns | Yes | The set. A single column carrying data-ui="accordion", data-size, data-variant and data-disabled, and the chrome that belongs to the set rather than to one item — the rule under the last one, the frame around them all, the air between cards. Its items are Collapsibles: a family beside this one, never a part of it, so nothing here selects into their DOM. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every accordion inside it.
Accordion tokens
| Token | Default |
|---|---|
--slotted-accordion-border-color | var(--slotted-accordion-rule-color, var(--slotted-border-subtle, ButtonBorder)) |
--slotted-accordion-gap | var(--_gap) |
--slotted-accordion-radius | var(--slotted-radius-md, 6px) |
--slotted-accordion-rule-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-accordion-shadow | none |
--slotted-accordion-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-disabled-foreground | Set per scheme by the theme |
--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 |