Tabs
Switch between views of the same context in place.
Tabs split one screen's content into peer views the reader moves between without leaving the page — Overview, Settings, Billing for a single project. For moving between different destinations, use navigation, not tabs.
Each Tab and its TabPanel are matched by a shared id.
<Tabs>
<TabList>
<Tab id="overview">Overview</Tab>
<Tab id="settings">Settings</Tab>
<Tab id="billing">Billing</Tab>
</TabList>
<TabPanels>
<TabPanel id="overview">Overview content</TabPanel>
<TabPanel id="settings">Settings content</TabPanel>
<TabPanel id="billing">Billing content</TabPanel>
</TabPanels>
</Tabs>Panels slide in the direction of travel, so keep the tab order matched to how the views relate.
When to use
Use Tabs to split one object's content into peer views the reader moves between in place.
Use something else when:
- The views are different destinations. Use navigation links.
- The options filter one list instead of swapping panels. Use Segment.
- The reader must complete each view in order. Use a sequence of steps.
- The sections stack down the page and the reader may open several or none. Use Disclosure.
Usage
Do
Keep every tab about the same object. Tabs promise the context stays fixed while the view changes.
Don't
Hide a required step behind a tab. If the reader must complete each view in turn, use a sequence, not tabs they can skip.
Props
Tabs
| Prop | Type | Default |
|---|---|---|
childrenThe children of the component. A function may be provided to alter the children based on | TypeChildrenOrFunction<TabsRenderProps> | Default— |
classNameThe CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the | TypeClassNameOrFunction<TabsRenderProps> | Default— |
defaultSelectedKeyThe initial selected keys in the collection (uncontrolled). | TypeKey | Default— |
disabledKeysThe item keys that are disabled. These items cannot be selected, focused, or otherwise | TypeIterable<Key> | Default— |
isDisabledWhether the TabList is disabled. | Typeboolean | Default— |
keyboardActivationWhether tabs are activated automatically on focus or manually. | Type"automatic" | "manual" | Default'automatic' |
orientationThe orientation of the tabs. | Type"horizontal" | "vertical" | Default'horizontal' |
selectedKeyThe currently selected key in the collection (controlled). | TypeKey | Default— |
TabList
| Prop | Type | Default |
|---|---|---|
childrenThe contents of the collection. | TypeReactNode | ((item: T) => ReactNode) | Default— |
classNameThe CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the | TypeClassNameOrFunction<TabsRenderProps> | Default— |
dependenciesValues that should invalidate the item cache when using dynamic collections. | Typereadonly any[] | Default— |
itemsItem objects in the collection. | TypeIterable<T> | Default— |
Tab
| Prop | Type | Default |
|---|---|---|
childrenThe children of the component. A function may be provided to alter the children based on | TypeChildrenOrFunction<TabsRenderProps> | Default— |
classNameThe CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the | TypeClassNameOrFunction<TabsRenderProps> | Default— |
hrefA URL to link to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href). | Typestring | Default— |
idThe unique id of the tab. | TypeKey | Default— |
isDisabledWhether the tab is disabled. | Typeboolean | Default— |
relThe relationship between the linked resource and the current page. See | Typestring | Default— |
targetThe target window for the link. See | TypeHTMLAttributeAnchorTarget | Default— |
TabPanels
| Prop | Type | Default |
|---|---|---|
childrenThe contents of the collection. | TypeReactNode | ((item: T) => ReactNode) | Default— |
classNameThe CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the | TypeClassNameOrFunction<TabsRenderProps> | Default— |
dependenciesValues that should invalidate the item cache when using dynamic collections. | Typereadonly any[] | Default— |
itemsItem objects in the collection. | TypeIterable<T> | Default— |
TabPanel
| Prop | Type | Default |
|---|---|---|
childrenThe children of the component. A function may be provided to alter the children based on | TypeChildrenOrFunction<TabsRenderProps> | Default— |
classNameThe CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the | TypeClassNameOrFunction<TabsRenderProps> | Default— |
idThe unique id of the tab. | TypeKey | Default— |
shouldForceMountWhether to mount the tab panel in the DOM even when it is not currently selected. Inactive tab | Typeboolean | Defaultfalse |
Accessibility
Tabs wraps React Aria's Tabs, so the list is a tablist navigated with the
arrow keys and each panel is linked to its tab. Selection follows focus and the
active panel is the only one in the tab order.
When the reader prefers reduced motion, the panel slide and the height change between panels are skipped, and a tab's colour change is instant when it is reached with the keyboard.