Tabs
Twilio's Tabs component.
- Status
- alpha
- Version
- 2.0.3
- Import from
@twilio-paste/core/tabs— or —@twilio-paste/tabs
Using alpha components in your product
Alpha components are ready for you to use in production. Components such as Tabs are likely to not see any API changes. This is only an alpha due to the lack of documentation and minimal design. Feel free to share your experience using this component at #help-design-system or start a discussion on GitHub.
Guidelines#
About Tabs#
The Tabs component allows a user to flip through multiple views within the same page.
Examples#
Horizontal Tabs#
Fitted Tabs#
Fitted tabs allow the tabs to expand and fit the width of a containing element.
Using state hooks#
🚨 ATTENTION!! 🚨
If you decided to use state hooks, the Paste team is NOT responsible for debugging any issues in your application.
The state prop allows you to hook into, and keep in sync the state of the Tabs and the state of your application.
This will allow you to set initial state and merge the returned state from the hook with the application state, and keep it in sync with user interactions.
You could use this if you want to add functionality to a button within the tab content. In the example below we're
using the select function from the tab state to advance to the next tab, and go back to the previous tab.
Anatomy#
| Property | Default token | Modifiable? |
|---|---|---|
| Tab label text |
| No |
| Tab Label box |
| No |
| Tab List Border |
| No |
Usage Guide#
API#
Installation#
yarn add @twilio-paste/tabs - or - yarn add @twilio-paste/coreUsage#
import {Tabs, TabList, Tab, TabPanels, TabPanel} from '@twilio-paste/tabs';const HorizontalTabsExample: React.FC = () => { const selectedId = useUID(); return ( <Tabs selectedId={selectedId} baseId="horizontal-tabs-example"> <TabList aria-label="My tabs"> <Tab>Tab 1</Tab> <Tab disabled>Tab 2</Tab> <Tab id={selectedId}>Tab 3</Tab> </TabList> <TabPanels paddingTop="space20"> <TabPanel>Tab 1</TabPanel> <TabPanel>Tab 2</TabPanel> <TabPanel>Tab 3</TabPanel> </TabPanels> </Tabs> );};Tabs Props#
variant?: 'fitted' | undefined (default)
Changes the Tabs' to either fit the width of the containing element or not.
selectedId?: string | null
Tells the Tabs which panel to load when it mounts. Important to provide, otherwise the first render may be a little delayed.
baseId?: string
Sets the prefix for the auto-generated ids on each Tab and TabPanel. Useful for consistent renders, like for tests.
TabList Props#
aria-label: string
Required label for this Tabs component. Titles the entire Tabbing context for screen readers.
Tab Props#
id?: string | undefined
Same as the HTML attribute.
focusable?: boolean | undefined
When an element is disabled, it may still be focusable. It works similarly to readOnly on form elements. In this case, only aria-disabled will be set.
disabled?: boolean | undefined
Same as the HTML attribute.
TabPanels Props#
None available.
TabPanel Props#
id?: string | undefined
Same as the HTML attribute.
tabId?: string | undefined
The ID of the Tab component this Panel pairs with.