Skip to content

Accordion

import { Accordion } from '@yarcl/react';

Orders ship within two working days.

Free returns within 30 days of delivery.

Coming soon.

Two years on every product.

<Accordion type="single" defaultValue="shipping">
<Accordion.Item value="shipping">
<Accordion.Trigger>Shipping</Accordion.Trigger>
<Accordion.Content>Orders ship within two working days.</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="returns">
<Accordion.Trigger>Returns</Accordion.Trigger>
<Accordion.Content>Free returns within 30 days of delivery.</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="gift-cards" disabled>
<Accordion.Trigger>Gift cards</Accordion.Trigger>
<Accordion.Content>Coming soon.</Accordion.Content>
</Accordion.Item>
</Accordion>

With type="single", opening an item closes the others. Clicking the open item closes it; set collapsible={false} to keep one item open at all times.

Wrap the trigger in Accordion.Header to place a drag handle, status or menu beside it. These controls are siblings of the trigger button, so they remain independently focusable. Hovering the trigger highlights the whole header row.

<Accordion.Item value="module-1">
<Accordion.Header
start={<button type="button" aria-label="Reorder module">⋮⋮</button>}
end={<span>Published</span>}
>
<Accordion.Trigger>Introduction</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content>Lessons in this module</Accordion.Content>
</Accordion.Item>

type="multiple" lets items open independently. Here the open items are controlled with value and onValueChange.

Open: Account

Name, email and password.

Email and push preferences.

Who can see your profile.

const [open, setOpen] = useState<string[]>(['account']);
<Accordion type="multiple" value={open} onValueChange={setOpen} size="sm" color="success">
<Accordion.Item value="account">…</Accordion.Item>
<Accordion.Item value="notifications">…</Accordion.Item>
</Accordion>
  • size sets the trigger height, padding, font size and icon size from your sizes.
  • radius rounds the outer frame, from your radii.
  • color tints the open item’s chevron, from your colors.
  • The frame and dividers use borders.width and the neutral border color.
  • Opening and closing animate with motion.base and motion.easing. With reduced motion preferred, panels open and close instantly.

All three props can be set per component in components.Accordion.

Follows the WAI-ARIA accordion pattern. Each Accordion.Trigger renders a button inside a heading (h3 by default; set level to fit your page outline). The button has aria-expanded and aria-controls, and each Accordion.Content is a region labelled by its trigger. Closed panels are hidden from assistive technology.

Key Action
Enter Space opens or closes the focused item
Tab moves to the next trigger or focusable content
↓ ↑ moves to the next or previous trigger, skipping disabled ones
Home End moves to the first or last trigger

Plus type, and value (controlled) or defaultValue (uncontrolled). With type="single" the value is a string or null and collapsible is available; with type="multiple" it is an array of strings.

PropTypeDefaultDescription
childrenReactNodeAccordion.Items.
colorColorconfigconfig.defaults.colorColor of the open item's indicator, from the colors config.
disabledbooleanDisables every item.
radius'size' | Radiusconfigconfig.defaults.radiusCorner radius of the outer frame, from the radii config, or 'size' to match the size.
size'lg' | 'xs' | 'sm' | 'md' | 'xl'config.defaults.sizeTrigger height, padding and font size, from the sizes config.
PropTypeDefaultDescription
value requiredstringIdentifies the item in the accordion's value.
disabledbooleanPrevents opening or closing this item.
PropTypeDefaultDescription
endReactNodeContent after the trigger, such as a badge or actions menu.
startReactNodeContent before the trigger, such as a drag handle.
PropTypeDefaultDescription
level3 | 2 | 4 | 1 | 5 | 63Level of the heading that wraps the button, to fit the page outline.