Accordion

Stacked sections that open and close, so people can scan titles and expand only what they need.

import { Accordion, AccordionItem } from '@halo-ds/react';

When to use it

Use an accordion to organise long content into sections: FAQs, settings groups, filters, or details that most people can skip. Each item is an Accordion item: a header with a title and a plus or minus button, and a content slot that opens below it, where you can put anything.

Accordion items have two states (collapsed and expanded) and four interactions. Stack as many as you need.

Do

  • Keep titles short and specific so people can scan them.
  • Use accordions for content most people can skip.
  • Open the first item when one section is most important.
  • Turn off the last divider inside cards.

Don't

  • Hide information everyone needs; show it on the page instead.
  • Nest accordions inside accordions.
  • Put the main action of a page inside a collapsed item.
  • Use an accordion for just one or two short sections.

Props

Accordion props

PropTypeWhat it does
type`AccordionType \undefined`single: opening one item closes the others. multiple: any number can be open.
defaultValue`string[] \undefined`Items open on first render (their values).
value`string[] \undefined`Controlled open items. Pair with onValueChange.
onValueChange`((value: string[]) => void) \undefined`
children (required)ReactNode
classNames`Partial<Record<AccordionPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<AccordionPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

AccordionItem props

PropTypeWhat it does
title (required)ReactNodeThe section title. Figma: Title.
children (required)ReactNodeThe content slot. Figma: Content. Put anything inside.
value`string \undefined`Identifies the item inside an Accordion. Defaults to an auto id.
defaultOpen`boolean \undefined`Open on first render when used on its own (outside an Accordion). Figma: State.
divider`boolean \undefined`Line under the item. Turn off for the last item inside a card. Figma: Divider.
disabled`boolean \undefined`
headingLevel`2 \3 \4 \5 \6 \undefined`Heading level for the title, to fit the page outline.

It also takes the usual HTML attributes for its element.

Examples

Overview

import { Accordion, AccordionItem } from '@halo-ds/react';

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 480 }}>
      <Accordion defaultValue={['billing']}>
        <AccordionItem value="billing" title="How does billing work?">
          You pay monthly for each member. Change or cancel any time.
        </AccordionItem>
        <AccordionItem value="data" title="Where is my data stored?">
          In Europe or the United States. You choose when you sign up.
        </AccordionItem>
        <AccordionItem value="export" title="Can I export my work?">
          Yes, as PDF, CSV or a full backup.
        </AccordionItem>
      </Accordion>
    </div>
  );
}

One open at a time

type="single" closes the open item when another opens.

import { Accordion, AccordionItem } from '@halo-ds/react';

export default function Demo() {
  return (
    <div style={{ width: '100%', maxWidth: 480 }}>
      <Accordion type="single" defaultValue={['a']}>
        <AccordionItem value="a" title="Shipping">Free on orders over $50.</AccordionItem>
        <AccordionItem value="b" title="Returns">Within 30 days, in the original box.</AccordionItem>
        <AccordionItem value="c" title="Warranty">Two years on every product.</AccordionItem>
      </Accordion>
    </div>
  );
}

Steps in a card

Inside a card, turn off the last divider. A disabled item can not be opened yet.

import { Accordion, AccordionItem, Card } from '@halo-ds/react';

export default function Demo() {
  return (
    <div style={{ width: '100%', maxWidth: 420 }}>
      <Card>
        <Accordion type="single" defaultValue={['address']}>
          <AccordionItem value="address" title="1. Shipping address">Ada Okafor, 12 Marina Road, Lagos.</AccordionItem>
          <AccordionItem value="delivery" title="2. Delivery">Standard, 3 to 5 days.</AccordionItem>
          <AccordionItem value="payment" title="3. Payment" disabled divider={false}>Complete delivery first.</AccordionItem>
        </Accordion>
      </Card>
    </div>
  );
}

More: https://halodesignsystem.dev/components/accordion