Components

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

Do
  • Write each trigger as the question or topic people scan for, so the headings alone tell them where to look.
  • Leave multiple off 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.
Don’t
  • 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>.

PropTypeDefault
variant
Hairline dividers only, or the items in a card.
'plain' | 'card''plain'
defaultValue
Items open at first, for uncontrolled use.
string[]—
value
Open items, for controlled use.
string[]—
onValueChange
Called when items open or close.
(value, details) => void—
multiple
Lets several items stay open.
booleanfalse
collapsible
With false, one item always stays open.
booleantrue
disabled
Stops every item from opening or closing.
booleanfalse
hiddenUntilFound
Keeps closed panels findable by find-in-page, which opens them.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AccordionItem

One section. Renders a <div>.

PropTypeDefault
value
Identifies the item in the accordion’s value.
string—
disabled
Stops the item from opening or closing.
booleanfalse
onOpenChange
Called before the item opens or closes.
(open, details) => void—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AccordionTrigger

The heading row with its chevron. Renders a <button> inside a heading.

PropTypeDefault
level
The heading level around the button.
2 | 3 | 4 | 5 | 63
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

AccordionPanel

The content, in a padded box inside a clipping panel. Renders a <div>.

PropTypeDefault
keepMounted
Keeps the panel in the DOM while closed.
booleanfalse
contentSx
Styles for the padded box inside.
StyleXStyles—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—