A vertically stacked list of headers that reveal or hide associated sections of content.
OUI exports 4 accordion-related components:
DisclosureGroup).import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
} from "@opengovsg/oui"<Accordion>
<AccordionItem>
<AccordionHeader>Accordion header</AccordionHeader>
<AccordionContent>Accordion content</AccordionContent>
</AccordionItem>
</Accordion>The Accordion component provides an accessible way to organize and display collapsible content sections.
Use the size prop on Accordion to change the size of the accordion.
Small
Medium (Default)
By default, only one accordion item can be expanded at a time. Use the allowsMultipleExpanded prop on the Accordion component to allow multiple items to be expanded simultaneously.
Use the defaultExpanded prop on AccordionItem to set an item as expanded by default.
Control the expanded state of the accordion using the expandedKeys and onExpandedChange props on the Accordion component.
Use the startContent prop on AccordionHeader to add content before the title, such as icons.
Use the indicator prop on AccordionHeader to customize the expansion indicator icon.
Use the hideIndicator prop on AccordionHeader to hide the indicator icon.
Use the isDisabled prop on AccordionItem to disable interaction with specific items.
The Accordion component wraps React Aria's DisclosureGroup component and provides styling variants. It accepts all props from DisclosureGroup plus the following:
| Prop | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "md" | The size of all accordion items. |
color | "main" | "main" | The color scheme of all accordion items. |
allowsMultipleExpanded | boolean | false | Whether multiple items can be expanded at the same time. |
expandedKeys | Set<string> | - | The expanded items (controlled). |
defaultExpandedKeys | Set<string> | - | The default expanded items (uncontrolled). |
onExpandedChange | (keys: Set<string>) => void | - | Handler called when the expanded items change. |
children | ReactNode | - | The accordion items. |
classNames | SlotsToClasses<AccordionSlots> | - | Custom classes for the accordion slots. |
The AccordionItem component wraps React Aria's Disclosure component. It accepts all props from Disclosure including:
| Prop | Type | Default | Description |
|---|---|---|---|
isDisabled | boolean | false | Whether the accordion item is disabled. |
defaultExpanded | boolean | false | Whether the accordion item is expanded by default (uncontrolled). |
isExpanded | boolean | - | Whether the accordion item is expanded (controlled). |
onExpandedChange | (isExpanded: boolean) => void | - | Handler called when the expanded state changes. |
children | ReactNode | - | The accordion header and content. |
classNames | SlotsToClasses<AccordionSlots> | - | Custom classes for the accordion item slots. |
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | (props: AccordionHeaderRenderProps) => ReactNode | - | The header title content. Supports render props. |
startContent | ReactNode | (props: AccordionHeaderRenderProps) => ReactNode | - | Content displayed before the title. Supports render props. |
endContent | ReactNode | (props: AccordionHeaderRenderProps) => ReactNode | - | Content displayed after the title. Supports render props. |
indicator | ReactNode | (props: AccordionHeaderRenderProps) => ReactNode | <ChevronDown /> | The expansion indicator icon. Supports render props. |
hideIndicator | boolean | false | Whether to hide the indicator icon. |
classNames | SlotsToClasses<...> | - | Custom classes for the header slots. |
When using render props for children, startContent, endContent, or indicator, the following props are available:
| Prop | Type | Description |
|---|---|---|
isExpanded | boolean | Whether the accordion item is currently expanded. |
isHovered | boolean | Whether the header button is hovered. |
isPressed | boolean | Whether the header button is pressed. |
isFocused | boolean | Whether the header button is focused. |
isFocusVisible | boolean | Whether the header button has keyboard focus visible. |
isDisabled | boolean | Whether the accordion item is disabled. |
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | The content to display inside the accordion panel. |
classNames | SlotsToClasses<"panel" | "content"> | - | Custom classes for the content slots. |
The Accordion component follows the ARIA disclosure pattern:
aria-expanded set to indicate the expanded state.aria-controls.