Accordion
A vertically stacked set of interactive headings that each reveal a section of content.
Installation
The component is exported from @by/experience-system. Add the package with your package manager:
pnpm add @by/experience-systemIn this monorepo, depend on the workspace package (for example via workspace:* or your catalog) so imports resolve to packages/experience-system.
Composition
Use the following composition to build an Accordion:
Accordion
├── AccordionItem
│ ├── AccordionTrigger
│ └── AccordionContent
└── AccordionItem
├── AccordionTrigger
└── AccordionContentAccordionTrigger wraps Radix Header and Trigger (with BY styling and a chevron); you do not render a separate header part. Radix props and semantics are documented in API Reference and the Radix Accordion docs.
Usage
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@by/experience-system';Accordion is a client component ('use client'). Use it inside a Client Component or a dynamic import when using the Next.js App Router.
<Accordion type="single" collapsible defaultValue="item-1">
<AccordionItem value="item-1">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionContent>
Yes. It follows the WAI-ARIA accordion pattern.
</AccordionContent>
</AccordionItem>
</Accordion>Examples
Basic
A single-open accordion with the first item open by default (same preview as at the top of the page).
Multiple
Use type="multiple" to allow more than one section to stay open.
Disabled
Use the disabled prop on AccordionItem to prevent expanding an item.
Borders
Add a border around the whole accordion. Items already use bottom borders; you can tune both for a framed look.
Card
Wrap the accordion in Card (and related layout parts) for a contained FAQ or settings block.
RTL
The experience system targets RTL via Tailwind logical properties and start/end utilities where appropriate. Set dir="rtl" on a parent (for example html or a layout region) so text and the trigger chevron align correctly. For project-wide RTL configuration, follow your app’s i18n and layout guidelines.
For Radix-specific behavior, see the Radix Accordion documentation.
API Reference
The tables below mirror the Radix UI Accordion API. Subsection titles name the exports from @by/experience-system; Radix part names are noted where they differ.
Accordion
Contains all parts of an accordion.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
type | 'single' | 'multiple' | — (required) |
value | string when type="single"; string[] when type="multiple" | Uncontrolled: omit. Controlled: current value(s). |
defaultValue | string or string[] | No default |
onValueChange | (value: string | string[]) => void | — |
collapsible | boolean | false (only applies when type="single"; when true, the open item can be closed) |
disabled | boolean | false |
dir | 'ltr' | 'rtl' | 'ltr' |
orientation | 'vertical' | 'horizontal' | 'vertical' |
| Data attribute | Values |
|---|---|
[data-orientation] | "vertical" | "horizontal" |
AccordionItem
One collapsible section.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
value | string | — (required) |
disabled | boolean | false |
| Data attribute | Values |
|---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
[data-orientation] | "vertical" | "horizontal" |
AccordionTrigger
Toggles the item. In Radix, Trigger must sit inside Header; this library composes both and adds the chevron. Trigger-level props apply to the inner Accordion.Trigger.
Header (internal):
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Trigger:
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Data attribute | Values |
|---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
[data-orientation] | "vertical" | "horizontal" |
AccordionContent
Collapsible panel for the item body.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
forceMount | boolean | — |
| Data attribute | Values |
|---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
[data-orientation] | "vertical" | "horizontal" |
| CSS variable | Description |
|---|---|
--radix-accordion-content-width | Content width while opening/closing (use for size animations) |
--radix-accordion-content-height | Content height while opening/closing (use for size animations) |
For keyboard interaction, accessibility roles, and additional examples, see the Radix UI Accordion documentation.
Source in the repo: packages/experience-system/src/components/Accordion/Accordion.tsx.