Accordion

A heading that opens and closes a region of content.

Demos

For usage examples, visit the component demo page: Accordion

Import

import { Accordion } from '@soroush.tech/design-system/Accordion'

Props

PropTypeDefaultDescription
childrenReactNode-An AccordionSummary, then what it opens.
isExpanded / defaultExpandedbooleanfalseWhether it is open - controlled with onChange, or at first.
onChange(event, isExpanded: boolean) => void-Fired when the summary is pressed, with the state it asks for.
disabledbooleanfalseStays as it is, and its summary is off.
hasGuttersbooleantrueSide padding on the summary, the details and the actions.
transitionComponentType<AccordionTransitionProps>CollapseThe transition that opens and closes the region.
borderRadiuskeyof Theme['radii']theme.defaults.surfaceRadius, else squareCorner radius.
bgkeyof Theme['background']'paper'Background.
textColorkeyof Theme['text']theme.defaults.textColor, else 'initial'Text color.
className, data-testidOn the root.

It takes the styled-system space props too.

The parts

PartWhat it is
AccordionSummaryThe button in a heading. expandIcon is the icon that turns; headingLevel its level.
AccordionDetailsThe padded body of the region.
AccordionActionsThe foot of the region: buttons at the end of a row.
AccordionGroupA column of accordions: the arrows, Home and End move between them; isExclusive keeps one open.

Each part reads the Accordion it sits in, and says so if it sits in none.

Keys

A summary is a button: Enter and Space open and close it. Inside an AccordionGroup:

KeyDoes
ArrowDown, ArrowUpNext and previous summary, round the ends; one that is off is skipped.
Home, EndThe first and the last summary.

Customization

theme.components.Accordion styles the root and the region; AccordionSummary its root (the heading), button, content and icon; AccordionDetails, AccordionActions and AccordionGroup their root. defaultProps set hasGutters, borderRadius, bg and textColor (Accordion), headingLevel (AccordionSummary) and isExclusive (AccordionGroup).

Source code

If this page does not answer your question, have a look at the implementation of the component for more detail.