Accordion

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

Source@chakra-ui/react

Import#

import { Accordion } from '@chakra-ui/react'

Usage#

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

<Accordion.Root padding='4'>
<Accordion.Item value='a'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 1 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value='b'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 2 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

Expand multiple items at once#

Set multiple to true to allow multiple accordion items to be expanded at once.

<Accordion.Root defaultValue={['section-1']} multiple padding='4'>
<Accordion.Item value='section-1'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 1 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value='section-2'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 2 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

Toggle each accordion item#

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

<Accordion.Root collapsible padding='4'>
<Accordion.Item value='section-1'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 1 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value='section-2'>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 2 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

Styling the expanded state#

The Accordion.Trigger component has aria-expanded set to true or false depending on the state of the Accordion.Item. Use the style prop _expanded to style this state.

<Accordion.Root padding='4'>
<Accordion.Item value='section-1'>
<h2>
<Accordion.Trigger _expanded={{ bg: 'tomato', color: 'white' }}>
<Span flex='1' textAlign='left'>
Click me to see a different style
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

Accessing the internal state#

If you need access to the internal state of each accordion item, you can use a render prop. The internal state provides open and disabled.

<Accordion.Root multiple padding='4'>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 1 title
</Span>
<Accordion.Indicator />
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item>
{(itemState) => (
<>
<h2>
<Accordion.Trigger>
<Span flex='1' textAlign='left'>
Section 2 title
</Span>
{itemState.open ? <FiMinus /> : <FiPlus />}
</Accordion.Trigger>
</h2>
<Accordion.Content pb='4'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
</Accordion.Content>
</>
)}
</Accordion.Item>
</Accordion.Root>

Accessibility#

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

Edit this page on GitHub

Proudly made inNigeria by Segun Adebayo

Deployed by â–² Vercel