Tabs

GuidelinesReactAccessibility

Accessibility

Tabs

Accessibility props

TabList

PropTypeDescription
ariaLabelstringAllows you to provide an accessible label for the set of tabs.
ariaLabelledbystringReferences the ID of an element that labels the set of tabs.

Tab

PropTypeDescription
disabledbooleanIndicates that the tab is not interactive and cannot be activated.

Accessibility implementation

  • Correct ARIA roles: tablist for the TabList, tab for individual tabs, and tabpanel for tab panels
  • Appropriate ARIA states and relationships:
  • aria-selected: Indicates which tab is currently active
  • aria-disabled: Applied to tabs that cannot be activated
  • aria-controls: Applied to each tab to reference its associated panel
  • aria-labelledby: Applied to each panel to reference its associated tab (this is different from the ariaLabelledby prop on TabList)

Keyboard navigation

  • Tab: Moves focus to the active tab panel
  • Arrow Right: Moves focus to the next tab in the list. When focus is on the last tab, it wraps to the first tab
  • Arrow Left: Moves focus to the previous tab in the list. When focus is on the first tab, it wraps to the last tab
  • Home: Moves focus to the first tab in the list
  • End: Moves focus to the last tab in the list

Best practices

  • Use the ariaLabel or ariaLabelledby props on the TabList component to provide a descriptive label for the set of tabs, especially when there are multiple tab sets on a page.
  • Ensure that tab labels are clear and descriptive of the content they control.
  • When a tab is disabled, use the disabled prop to properly communicate this state to assistive technologies.
  • Always translate accessibility-related strings to match the user’s language.

Code examples

Using ariaLabel

<Tabs>
<TabList ariaLabel="Content sections">
<Tab>Section 1</Tab>
<Tab>Section 2</Tab>
<Tab disabled>Section 3</Tab>
</TabList>
<TabPanels>
<TabPanel>Content for section 1</TabPanel>
<TabPanel>Content for section 2</TabPanel>
<TabPanel>Content for section 3</TabPanel>
</TabPanels>
</Tabs>

Using ariaLabelledby

<div>
<h2 id="tabs-title">Flight Options</h2>
<Tabs>
<TabList ariaLabelledby="tabs-title">
<Tab>Economy</Tab>
<Tab>Business</Tab>
<Tab>First Class</Tab>
</TabList>
<TabPanels>
<TabPanel>Economy class options</TabPanel>
<TabPanel>Business class options</TabPanel>
<TabPanel>First class options</TabPanel>
</TabPanels>
</Tabs>
</div>