Accordion
Sections that open from their headings, for answers, settings or an outline. Built on ui-sdk’s Accordion.
Usage
import {
Accordion,
AccordionItem,
AccordionPanel,
AccordionTrigger,
} from 'nyctoui/accordion'
<Accordion defaultValue={['billing']}>
<AccordionItem value="billing">
<AccordionTrigger>How does billing work?</AccordionTrigger>
<AccordionPanel>…</AccordionPanel>
</AccordionItem>
</Accordion>One item is open at a time unless you pass multiple. The value is always an array of open item values. Each trigger is a button inside a heading (an h3; set level to fit the page), so screen readers can jump between them. Tab moves between triggers; Enter or Space opens one. Panels animate their height on the same curve as Collapsible, and skip it under reduced motion.
Good for
- An FAQ on a pricing page, where each question opens its answer.
- Grouped settings in a mobile app, such as Notifications, Privacy and Storage, where only one group is open at a time.
- Order details in a shop’s account area: shipping, payment and items, each folded under its own heading.
- A course outline in a learning app, with lessons listed under each chapter.
Anatomy
<Accordion>
<AccordionItem>
<AccordionTrigger />
<AccordionPanel />
</AccordionItem>
</Accordion>Examples
Card
variant="card" puts the items in a card, for an accordion that sits on its own, as on a help page.
Multiple and controlled
With multiple several items stay open. Pass value and onValueChange to open them from elsewhere, such as an Expand all button.
Disabled
A disabled item stays focusable, so it is still read out, but can’t open or close.
Best practices
- Write each trigger as the question or topic people scan for, so the headings alone tell them where to look.
- Leave
multipleoff for FAQs and settings, where one open section is easier to follow. Turn it on when people compare sections side by side. - Open the section most people need with
defaultValue, so the page doesn’t start as a wall of closed rows. - Use
variant="card"or the plain dividers, not both plus a card of your own around each item.
- Hide something people must read or fill in to finish a task, such as a required field or a price change. Show it.
- Nest an accordion inside another one. Two levels of folding make content hard to find; split the page instead.
- Fold a single short paragraph. A section that takes one line to show doesn’t need a trigger.
API reference
Accordion
Holds which items are open. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
variantHairline dividers only, or the items in a card. | 'plain' | 'card' | 'plain' |
defaultValueItems open at first, for uncontrolled use. | string[] | — |
valueOpen items, for controlled use. | string[] | — |
onValueChangeCalled when items open or close. | (value, details) => void | — |
multipleLets several items stay open. | boolean | false |
collapsibleWith false, one item always stays open. | boolean | true |
disabledStops every item from opening or closing. | boolean | false |
hiddenUntilFoundKeeps closed panels findable by find-in-page, which opens them. | boolean | false |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
AccordionItem
One section. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
valueIdentifies the item in the accordion’s value. | string | — |
disabledStops the item from opening or closing. | boolean | false |
onOpenChangeCalled before the item opens or closes. | (open, details) => void | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
AccordionTrigger
The heading row with its chevron. Renders a <button> inside a heading.
| Prop | Type | Default |
|---|---|---|
levelThe heading level around the button. | 2 | 3 | 4 | 5 | 6 | 3 |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
AccordionPanel
The content, in a padded box inside a clipping panel. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
keepMountedKeeps the panel in the DOM while closed. | boolean | false |
contentSxStyles for the padded box inside. | StyleXStyles | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |