[ Navigation ]

Accordion

A vertically stacked list of headers that expand to reveal content. Smoothly animated, with single or multiple open panels, controlled or uncontrolled.

2 examplesDark modeAccessible

Import#

import { Accordion } from 'reusify-ui';

When to use#

  • FAQs and help content.
  • Long settings pages where users only need one section at a time.
  • Avoid hiding content users need to compare side by side.

Examples#

Single (default)#

Opening one panel closes the others. defaultValue sets which panels start open. Items use their index ("0", "1"…) unless you give them a value.

Yes. It is open source under the MIT license, free for personal and commercial projects.

No. Import reusify-ui/styles.css once and every component is styled. It also works alongside Tailwind.

Yes. Add the dark class (or data-theme="dark") to <html> and every component switches.

Override CSS variables like --ru-primary in your own stylesheet. See the Theming guide.
<Accordion
  defaultValue={['0']}
  items={[
    { title: 'Is Reusify UI free?', content: 'Yes, MIT licensed.' },
    { title: 'Do I need Tailwind CSS?', content: 'No. Just import the stylesheet.' },
    { title: 'Does it support dark mode?', content: 'Yes, add the dark class.' },
  ]}
/>

Multiple open#

Free delivery on orders above ₹999. Ships in 2 to 4 days.

Return anything within 30 days for a full refund.

<Accordion multiple defaultValue={['shipping', 'returns']} items={[
  { value: 'shipping', title: 'Shipping', content: '…' },
  { value: 'returns', title: 'Returns', content: '…' },
  { value: 'warranty', title: 'Warranty', content: '…', disabled: true },
]} />

API reference#

<Accordion />

items*-
AccordionItem[]

Sections to render (see below).

multiplefalse
boolean

Allow several panels open at once.

value-
string[]

Open panels (controlled).

defaultValue[]
string[]

Initially open panels (uncontrolled).

onChange-
(value: string[]) => void

Called with the open panel values.

<AccordionItem />

title*-
ReactNode

Header text.

content*-
ReactNode

Panel content.

valueindex
string

Stable id used in value / defaultValue.

disabled-
boolean

Header can't be toggled.

Accessibility#

  • Each header is a <button> inside an <h3> with aria-expanded and aria-controls.
  • Panels have role="region" labelled by their header. Closed panels are hidden from assistive tech and the Tab order.