Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Collapse Accordions in React

Using the <Accordion> – Tag in react implicitly generates bootstrap-elements from which I don’t know how to access them.

The structure is the following:

return (
<Card>
<Accordion>
<Accordion.Item eventKey={uniqueAccordionItemKey}>
<Accordion.Header>
</Accordion.Header>
<Accordion.Body>
</Accordion.Body>
</Accordion.Item>
</Accordion>
</Card>
);

From this many Accordions are being generated. I want a possibility to collapse all of them. How do I do so?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to manipulate the css-attributes using show and collapse as attributes but this turned out just hiding the content and not collapsing the Accordion.
Also manipulating the aria-expanded attribute inside the Accordion.Item did not work.

>Solution :

Have a look at https://react-bootstrap.netlify.app/docs/components/accordion/#accordion

You can control the accordion items using the activeKey prop on the Accordion in combination with the eventKey on the Accordion.Item

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading