Multi-open accordion with locked panels and keyboard support
A smart thermostat app has a What’s new screen listing firmware releases. Owners often compare two releases side by side, so several can be open at once. Some releases are locked: a beta that only testers can read, and a recalled version whose notes were pulled. Build the screen as an accessible accordion with full keyboard support.
The starter code includes the releases and the ones open on load:
const RELEASES = [
{ id: 'v4-0', version: 'Version 4.0 beta', notes: 'Room-by-room zones ...', locked: true },
{ id: 'v3-2', version: 'Version 3.2', notes: 'Eco presets lower the target ...' },
{ id: 'v3-1', version: 'Version 3.1', notes: 'Humidity readings no longer drift ...' },
{ id: 'v3-0', version: 'Version 3.0', notes: 'This release drained batteries ...', locked: true },
{ id: 'v2-9', version: 'Version 2.9', notes: 'The idle screen shows the outdoor temperature ...' },
];
const INITIAL_OPEN_IDS = ['v3-2', 'v2-9'];
<button> whose text is the version, placed alone inside a heading element (for example <h3>). A decorative arrow or lock icon is fine with aria-hidden="true".id, aria-expanded="true" or "false", and aria-controls set to its panel’s id.role="region" and aria-labelledby set to its button’s id, and contains the notes. Collapsed panels stay in the DOM but are hidden (the hidden attribute or display: none).INITIAL_OPEN_IDS start open. Clicking a header toggles only that section.disabled header button, aria-expanded="false", and a panel that is always hidden. They never open.When focus is on a header button, these keys move focus between the unlocked headers only (a disabled button can’t take focus):
Load 3.2 and 2.9 open; 3.1 closed; 4.0 beta and 3.0 locked
Click "Version 3.1" 3.1, 3.2 and 2.9 open
Click "Version 3.2" only 3.2 closes
Click "Collapse all" every section closed
Click "Expand all" 3.2, 3.1 and 2.9 open; locked ones stay closed
Focus "Version 3.1", ArrowDown focus skips 3.0 and lands on "Version 2.9"
ArrowDown again focus stays on "Version 2.9"
Home focus moves to "Version 3.2" (4.0 beta is locked)
RELEASES.preventDefault() on the navigation keys so they don’t also scroll the page.display on a panel overrides the hidden attribute. Don’t give panels a display rule.The tests click your buttons, dispatch keydown events (key: 'ArrowDown', 'ArrowUp', 'Home', 'End') on the focused header, and read the page like a screen reader would. You don’t need test ids or class names. The test frame is hidden, so the tests track focus through element.focus() calls and document.activeElement: move focus with .focus(). They check that:
version, in order, each inside an h1–h6 (or role="heading") that doesn’t contain the notes.aria-expanded and disabled state is correct after every click.aria-controls points to an element on the page with role="region", whose aria-labelledby is the button’s id and which contains the notes.hidden, display: none, visibility: hidden, or aria-hidden="true").document.activeElement is the expected header after each navigation key.Capitalization and extra spacing don’t matter.