Coding task · JavaScript and React course · Module 13: Testing React

Practice: Tab Navigation

The ARIA tabs pattern consists of a tablist, several tabs and a tabpanel. aria-selected tells a screen reader which tab is active, and React Testing Library lets you find it with getByRole('tab', { selected: true }). The panel points at its tab with aria-labelledby, which gives it an accessible name, and the tab points at the panel with aria-controls. The colour of the active tab alone is not enough: the test and assistive technologies do not see it.

Task

Finish the ARIA tabs of the commander console. ___BLANK1___: every tab button has the tab role (the container already has role="tablist" and the content role="tabpanel"), so the test finds the tabs with getAllByRole('tab'). ___BLANK2___: isActive is true only for the tab whose id equals activeId; it goes into aria-selected and the style. ___BLANK3___: clicking a tab stores its id in the state. The test checks that the first tab is selected at the start, that the selection moves after a click, and that the panel shows the content of the selected tab and has its name (aria-labelledby).