Robust and Accessible Accordion Component
Modern web applications frequently need to organize large amounts of content efficiently, presenting information in a structured, user-friendly manner without overwhelming the user. An Accordion component is a fundamental UI element that addresses this challenge by allowing users to toggle the visibility of content sections. This problem focuses on building a highly flexible, accessible, and performant Accordion component capable of managing diverse content and interactions, a critical skill for L5 engineers.
Your primary task is to implement a reusable Accordion component in React.
Accordion component that accepts an array of item data. Each item should have a clickable header that toggles the visibility of its corresponding content panel.Accordion must operate as a controlled component. It should accept openItemIds (an array of IDs of currently open items) and an onToggle callback prop. The onToggle callback should be invoked with the updated openItemIds whenever an item's header is clicked.multipleOpen boolean prop.
multipleOpen is true, multiple accordion items can be open simultaneously.multipleOpen is false (default), only one item can be open at a time. Clicking a new item's header should close the currently open item.Tab and Shift+Tab. Space or Enter keys on a focused header should toggle its content.role="heading", aria-expanded, aria-controls, aria-labelledby, role="region") to ensure screen reader compatibility.Accordion component is correctly implemented and renders with the provided mock data.openItemIds and onToggle props are correctly handled for controlled behavior.multipleOpen prop correctly enforces single or multiple open items.Tab, Shift+Tab, Space, Enter) works as expected for headers.Constraints
Accordion component itself; the App component will primarily manage the openItemIds state.multipleOpen prop)?Loading editor...