Skip to main content

Expanding items initially

You could use the initialEntered prop of AccordionItem to expand items when accordion first mounts. In the following example, the first and last item are expanded on mount.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Suspendisse massa risus, pretium id interdum in, dictum sit amet ante. Fusce vulputate purus sed tempus feugiat.
import { Accordion, AccordionItem } from '@szhsin/react-accordion';

export default function Example() {
return (
<Accordion>
<AccordionItem header="What is Lorem Ipsum?" initialEntered>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</AccordionItem>

<AccordionItem header="Where does it come from?">
Quisque eget luctus mi, vehicula mollis lorem. Proin fringilla
vel erat quis sodales. Nam ex enim, eleifend venenatis lectus
vitae, accumsan auctor mi.
</AccordionItem>

<AccordionItem header="Why do we use it?" initialEntered>
Suspendisse massa risus, pretium id interdum in, dictum sit amet
ante. Fusce vulputate purus sed tempus feugiat.
</AccordionItem>
</Accordion>
);
}
info

The Accordion component also has an initialEntered prop which can make every accordion item expanded when initially mounted.

When the initialEntered prop is specified on an individual AccordionItem at the same time, it overrides the initialEntered prop of Accordion component.