The Accordion component allows users to show and hide sections of related content on a page. It uses a composable API with separate components for root, item, trigger, and content.
import { Accordion } from '@raystack/apsara';
export default function Example() {
return (
<Accordion defaultValue="item-1">
<Accordion.Item value="item-1">
<Accordion.Trigger>Is it accessible?</Accordion.Trigger>
<Accordion.Content>
Yes. It adheres to the WAI-ARIA design pattern.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="item-2">
<Accordion.Trigger>Is it styled?</Accordion.Trigger>
<Accordion.Content>
Yes. It comes with default styles that can be customized.
</Accordion.Content>
</Accordion.Item>
</Accordion>
);
}
Multiple items open
<Accordion multiple defaultValue={["item-1", "item-2"]}>
<Accordion.Item value="item-1">
<Accordion.Trigger>First section</Accordion.Trigger>
<Accordion.Content>First content</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="item-2">
<Accordion.Trigger>Second section</Accordion.Trigger>
<Accordion.Content>Second content</Accordion.Content>
</Accordion.Item>
</Accordion>
API reference
Accordion (Root)
The root container component for the accordion.
Whether multiple items can be open at the same time.
The controlled value of the accordion. Use string for single mode, string array for multiple mode.
The default value when uncontrolled. Use string for single mode, string array for multiple mode.
onValueChange
(value?: string | string[]) => void
Callback fired when the accordion value changes. Receives string for single mode, string array for multiple mode.
Additional CSS class for the accordion root.
Accordion.Item
An individual accordion item.
A unique value for the item.
Additional CSS class for the accordion item.
Whether the accordion item is disabled.
Accordion.Trigger
The button that toggles the accordion item.
Additional CSS class for the trigger.
The content of the trigger button.
Accordion.Content
The collapsible content area.
Additional CSS class for the content wrapper.
The content to display when expanded.