# 830 MINAccessible Accordion
# 8
30 MIN
Overview
Build an accessible accordion component that uses semantic headings and buttons, manages aria-expanded/aria-controls, supports smooth height transitions, and allows either single-section or multiple-section open modes.
Requirements
- Render all accordion items closed initially.
- Open an item when its header button is clicked.
- Close an item when its header button is clicked again.
- If
multiple=false, ensure only one item can be open at a time. - If
multiple=true, allow multiple items to be open simultaneously. - Manage proper
aria-expanded,aria-controls, andaria-hiddenattributes for accessibility. - Support smooth height transitions when opening and closing items.
App.tsxdoes not need to be modified, although you may edit it to test themultiple={true}behavior.- You can use
datato populate the accordion items.
Notes
- You may use
useRefto measure the content height if you want to implement smooth CSS height transitions. - Keep track of the open item(s) in state and update them when an item is toggled.
- Ensure proper accessibility: keyboard navigation should work and screen readers should correctly interpret the accordion state.
- You don’t need to pass an
idtoAccordionItem. React provides theuseIdhook for generating stable IDs. - The prop types for
AccordionandAccordionItemare already provided. - You can use
datato populate the accordion items.
Tests
- renders all items closed initially
- opens an item when clicked
- closes an item when clicked again
- only one item stays open when multiple=false
- multiple items can be open when multiple=true