Tabs

An accessible tabs component.

The Tab and TabPanel elements are associated by their order in the tree. None of the components are empty wrappers, each is associated with a real DOM element in the document, giving you maximum control over styling and composition.

Import#

Tabs#

You can render any other elements you want inside of Tabs, but TabList should only render Tab elements, and TabPanels should only render TabPanel elements.

one!

Editable Example

Tabs expects TabList and TabPanels as children. The order doesn't matter, you can have tabs on the top or the bottom. In fact, you could have tabs on both the bottom and the top at the same time. You can have random elements inside as well.

Tab variants and color#

Tabs come in 6 different variants to style the tabs: line,enclosed, enclosed-colored, soft-rounded, solid-rounded

one!

Editable Example

Manually Activated Tabs#

By default, Tabs are activated automatically. This means when you use the arrow keys to change tabs, the tab is activated and focused.

The content of a TabPanel should ideally be preloaded. However, if switching to a tab panel causes a network request and possibly a page refresh, there might be some notable latency and this might affect the experience for keyboard and screen reader users.

In this scenario, you should use a manually activated tab, it moves focus without activating the tabs. With focus on a specifc tab, users can activate a tab by pressing Space or Enter.

one!

Editable Example

Tab sizes#

You can change the size of the tab by passing size prop. We support 3 sizes sm, md, lg

one!

Editable Example

Tab alignment#

You can change the alignment of the TabList by passing align prop. We support 3 sizes start, center, end.

one!

Editable Example

Fitted Tabs#

Stretch the tab list to fit the container by passing isFitted prop.

one!

Editable Example

Tabs onChange#

Calls back with the tab index whenever the user changes tabs, allowing your app to synchronize with it.

The Primary Colors
Editable Example

Tabs defaultIndex#

Starts the tabs at a specific index.

Editable Example

Tabs Index#

Like form inputs, a tab's state can be controlled. Make sure to include an onChange as well, or else the tabs will not be interactive.

Click the tabs or pull the slider around

Editable Example

Tab isSelected#

Because TabList needs to know the order of the children, we use cloneElement to pass state internally. If you want to know if a tab is active, you can wrap it, and then inspect clone props passed in.

1
Editable Example

Tab isDisabled#

When a Tab is disabled, it's skipped from the keyboard navigations and not clickable.

1
Editable Example

DataTabs#

If you'd like to drive your tabs with an array instead of using the granular components, you can create your own DataTabs component.

Perhaps the greatest dish ever invented.
Editable Example

Accessibility#

Keyboard#

KeyAction
ArrowLeftMoves focus to the next tab
ArrowUpMoves focus to the previous tab
TabWhen focus moves into the tab list, places focus on the active tab element
Space or EnterActivates the tab if it was not activated automatically on focus
HomeMoves focus to the first tab
EndMoves focus to the last tab

ARIA roles#

ComponentAriaUsage
Tabrole="tab"Indicates that it's a tab
aria-selectedSet to true a tab is selected and all other Tabs have it set to false.
aria-controlsSet to the id of its associated TabPanel
TabListidThe id of the TabPanel that's referencd by its associated Tab
aria-orientationSet to vertical or horizontal based on the value of the orientation prop.
role="tablist"Indicates that it's a tablist
aria-labelledbySet to the id of the Tab that labels the TabPanel.

Proudly made in 🇳🇬

Released under the MIT License.

Copyright © 2019 Segun Adebayo