Skip to content
Slotted

Accordion

A set of sections that expand and collapse, with one or several open at a time and a keyboard path between headers.

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

Accepted within 30 days of delivery, with the original packing slip.

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.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { 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.

14 pallets arrive today between 08:00 and 15:00.

6 pallets wait in dock 3 for a bin assignment.

Aisles 12 to 15 are due this week.

The 16:30 carrier pickup holds 38 parcels.

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.

Harbor & Pine Supply Co., customer since 2019.

Mira Alvarez, purchasing, and Tomas Berg, accounts payable.

Net 30, with a 2% discount when paid within 10 days.

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.

variant="plain"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
variant="ruled"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
variant="framed"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
variant="separated"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

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.

size="sm"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
size="md"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
size="lg"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

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.

indicator="chevron"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
indicator="plus-minus" togglePlacement="start"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
indicator="none"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

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.

headingLevel="2"

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
headingLevel="none"
Scheduled for September 12 with Harbor Freight, tracking HF-48213.
Invoice INV-20877 for $2,146.50, due October 4.

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.

mount="active"

mount="lazy"

mount="eager"

mount="until-found"

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.

disabled

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.
disabled on one item

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

Released by finance on October 1.

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.

Open: delivery. Last change by the reader: none.

Scheduled for September 12 with Harbor Freight, tracking HF-48213.

Invoice INV-20877 for $2,146.50, due October 4.

Accepted within 30 days of delivery, with the original packing slip.

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.

14 pallets arrive today between 08:00 and 15:00.

6 pallets wait in dock 3 for a bin assignment.

Aisles 12 to 15 are due this week.

Moved to cold storage on September 30.

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.

From the defaults

Requested by Mira Alvarez for $12,480.00.

Credit of $1,036.80 issues after inspection.
variant="plain" on the set

Requested by Mira Alvarez for $12,480.00.

Credit of $1,036.80 issues after inspection.

Accessibility

KeyEffectFocus
Entertoggles the panel of the focused header; with `multiple` off, the panel that was open closes with the reason `select`stays on the trigger
Spacethe same as Enterstays on the trigger
Tabmoves to the next focusable element; every focusable element in the accordion is in the page tab sequencethe next focusable element
Shift+Tabmoves to the previous focusable element, under the same rulethe previous focusable element
ArrowDownmoves to the next header and wraps at the end when loop is on; opens nothingthe header moved to
ArrowUpmoves to the previous header and wraps at the start when loop is on; opens nothingthe header moved to
Homemoves to the first header that is not disabledthe first enabled header
Endmoves to the last header that is not disabledthe 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.
multiplebooleanDefault false
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.
requireOpenbooleanDefault false
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.
loopbooleanDefault true
On Accordion, AccordionDefaultsProviderWhether the arrow keys wrap past the ends of the set.
size'sm' | 'md' | 'lg'Default md
On Accordion, AccordionDefaultsProviderThe step every item sits at, and the air between cards under separated.
variant'plain' | 'ruled' | 'framed' | 'separated'Default ruled
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'Default chevron
On Accordion, AccordionDefaultsProviderThe mark every header carries, handed to each item.
togglePlacement'end' | 'start'Default end
On Accordion, AccordionDefaultsProviderWhich side of the words that mark stands on, handed to each item.
headingLevel'none' | '1' | '2' | '3' | '4' | '5' | '6'Default 3
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'Default eager
On Accordion, AccordionDefaultsProviderWhen each panel’s content exists, handed to every item.
truncatebooleanDefault false
On Accordion, AccordionDefaultsProviderClips every title to one line instead of letting the row grow.
disabledbooleanDefault false
Reaches every item, and every trigger as the native attribute.

Events

NamePayloadWhen
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 setthe element’s own eventsWhenever 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

PartElementRequiredPurpose
rootdiv, or the element render returnsYesThe 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

TokenDefault
--slotted-accordion-border-colorvar(--slotted-accordion-rule-color, var(--slotted-border-subtle, ButtonBorder))
--slotted-accordion-gapvar(--_gap)
--slotted-accordion-radiusvar(--slotted-radius-md, 6px)
--slotted-accordion-rule-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-accordion-shadownone
--slotted-accordion-surfacevar(--slotted-surface-raised, Canvas)

Theme tokens it reads

TokenDefault
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-radius-md6px
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-surface-raisedSet per scheme by the theme