We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium frontend problem, graded against 5 test cases (2 of them hidden).
React and browser-platform problems - hooks, event handling, and rendering behaviour.
Reach for it when you see: A component, hook, or DOM-behaviour question rather than an algorithm.
More Frontend problems →The bug-prone version toggles the clicked panel and then loops to close the others - which double-handles the clicked one and lets `aria-expanded` and `hidden` disagree. The clean version:
1. Read whether the target is currently open.
2. Define `open(i) = i === index && !wasOpen`.
3. Loop once over all pairs writing both the button's `aria-expanded` and the panel's `hidden` from `open(i)`.
Using `aria-controls` to find the panel (instead of "the next sibling" or "panel i") is what keeps this working when the markup changes - and it is the relationship assistive tech already uses.
Time: O(panels).
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.