Tabs
Tabs allows the user to switch between content sections.
Overview
Tabs are primarily used to switch between panels of content, therefore, if you are using more than three tabs, it may be more appropriate to consider an Accordion. Tabs are based on the Card component and have similar behaviour in terms of elevation. They can be used in place of a Card, or inside a Card as an inline component.
Usage
Tabs are a combination of components that are composed together. Linking the tabs to panels is taken care of by the Tabs component.
Edit live code
Content
Tab content should be related content that is separated into, at most, a few sections. Ideally, no more than 3-4 tabs should be used. Tabs should be checked on a small device to ensure content can comfortably fit.
Content should not flow from one tab to another or be used to compare content as only one panel of content can be viewed at a time.
Accessibility
Keyboard Navigation
Similar to Radio Field, tabs can be navigated with the left and right arrow keys (opens in new window) . This will select a new tab and change the content to the corresponding panel. The active tab will be the only tabbable element, so the user can easily tab to other elements on the page.
Variations
Default selected
You can set the default selected tab with the defaultSelected prop.
Edit live code
Controlled
Tabs manage their own state by default, but they can also be manually controlled using value and onSelected.
Edit live code
Inline
Like Cards, tabs that are placed inside of a raised component can be flattened by using adding the inline property.
Edit live code
Properties
Tabs
Name | Values | Default |
---|---|---|
defaultSelectedAn zero based index of the default active tab | Number | |
valueAn zero based index of the current active tab, use with onSelected | Number | |
onSelectedA callback function that will receive the selected tab index | Function | |
inline | Boolean | false |
... | JSX.IntrinsicElements["div"] |
TabList
Name | Values | Default |
---|---|---|
... | JSX.IntrinsicElements["ul"] |
Tab
Name | Values | Default |
---|---|---|
onClickCalled in addition to selecting a tab. e.g. analytics | Function | |
... | JSX.IntrinsicElements["li"] |
TabPanel
Name | Values | Default |
---|---|---|
... | JSX.IntrinsicElements["section"] |