Frontend live coding · 25 minutes
Tabs with keyboard support
Build a tabs component in React in 25 minutes, with no UI library. It shows a row of tabs and one panel at a time, and a click on a tab shows its panel. It must follow the standard tabs pattern for keyboard and screen reader users. Start with the simplest version that works, then add the keyboard support. Explain your decisions while you code, as in a live round.
Requirements
- A row of tabs and one visible panel; a click on a tab selects it
- Roles: tablist on the container, tab on each tab, tabpanel on each panel
- The selected tab has aria-selected true and aria-controls with the id of its panel; the panel has aria-labelledby with the id of its tab
- Only the selected tab has tabindex 0 and the others have -1, so the Tab key leaves the tab list and goes to the panel
- A panel with no focusable content has tabindex 0, so the keyboard can reach it
- Left and Right arrows move focus between tabs and wrap at the ends; Home and End go to the first and the last tab
- The API takes a list of items, or composed children, and an optional default tab
What reviewers look for
What reviewers look for, the checklist and the stretch goals opens with a year in the app. What a year includes