Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Accordion

Accordion is used to display a list of high-level options that can expand/collapse to reveal more information.

Accordion components

  • Accordion: The wrapper that uses cloneElement to pass its prop to AccordionItem.
  • AccordionItem: A single accordion item.
  • AccordionHeader: It is used to toggle the expand/collapse state of the accordion item.
  • AccordionPanel: The container for the details to be revealed.
  • AccordionIcon: A chevron-down icon that rotates based on the expand/collapse state.

Import

Usage

By default, only one item may be expanded and it can only be collapsed again by expanding another.

EDITABLE EXAMPLE

Expand multiple items at once

If you set allowMultiple to true, then the accordion will permit multiple items to be expanded at once.

If you pass this prop, ensure that the index or defaultIndex prop is an array.

EDITABLE EXAMPLE

Toggle each accordion item

If you set allowToggle to true, any expanded item may be collapsed again.

EDITABLE EXAMPLE

Styling the expanded state

The AccordionItem component has the render prop isExpanded set to true or false.

EDITABLE EXAMPLE

Accessing the internal state

If you need access to the internal state of each accordion item, you can use a render prop. It provides 2 internal state: isDisabled and isExpanded`.

EDITABLE EXAMPLE

Accessibility

Pressing space or enter when focus is on the accordion panel header will toggle (expand or collapse) the accordion.

Props

Accordion

NameTypeDefaultDescription
allowMultiplebooleanfalseIf true, multiple accordion items can be expanded at once.
allowTogglebooleanfalseIf true, any expanded accordion item can be collapsed again.
indexnumber | arrayThe index(es) of the expanded accordion item.
defaultIndexnumber | arrayThe initial index(es) of the expanded accordion item.
onChangefunctionA callback invoked when accordion items are expanded or collapsed.
childrenReactNodeThe content of the accordion. The children must be one of the AccordionHeader and AccordionPanel components.

AccordionItem

NameTypeDefaultDescription
idstringA unique id for the accordion item.
isOpenbooleanfalseIf true, expands the accordion in the controlled mode.
defaultIsOpenbooleanfalseIf true, expands the accordion by on initial mount.
isDisabledbooleanfalseIf true, the accordion header will be disabled.
onChangefunctionA callback fired when the accordion is expanded/collapsed.
childrenReactNode | (RenderProps) => ReactNodeThe content of the accordion. The children must be one of the AccordionHeader and AccordionPanel components.

AccordionHeader

AccordionPanel