Question presented to candidate: "Build a reusable Tabs component. It takes a list of tabs, shows one panel at a time, and lets the user switch by clicking or with the keyboard. It should follow the WAI-ARIA tabs pattern so screen-reader and keyboard users get the same experience as mouse users."
Requirements:
- Driven by a config array (
id,label, content); adefaultActiveid picks the first selected tab, falling back to the first tab. - Clicking a tab selects it and shows its panel; only the selected panel is visible.
- WAI-ARIA roles and wiring:
tablistwith an accessible name,tabbuttons witharia-selectedandaria-controls,tabpanelelements witharia-labelledby. - Roving tabindex: only the selected tab is in the Tab order (
tabindex="0"); the others have-1. - Keyboard: Arrow Right and Arrow Left move to the next and previous tab and wrap; Home and End go to the first and last; focus and selection move together (automatic activation).
- Switching tabs must not lose what the user typed in a panel.
What a strong answer should cover:
- One piece of state (the active id); everything else (which panel shows,
aria-selected,tabindex) derived from it. - The roles, the id wiring between tabs and panels, and why a
tablistneeds a label. - Roving tabindex: why Tab should enter the tab list once and then jump to the panel, while arrows move inside the list.
- Automatic versus manual activation and when each is appropriate.
- Hiding inactive panels (
hidden,v-show) versus unmounting them, and the effect on panel state.
Clarifying questions expected:
- "Should arrow keys select a tab immediately, or only move focus until Enter is pressed?"
- "Can tabs be disabled, added or removed at runtime?"
- "Is it fine to render every panel up front, or are some panels expensive?"
Code / implementation expected: Yes. A working component with a three-tab demo, one of which holds a form field to prove state survives switching.