Skip to content
Paste
UX Platform
Change the site theme
GitHub

Tabs

Twilio's Tabs component.

Status
alpha
Version
2.0.3
Sources
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#

Tab 1Tab 2Tab 3

Fitted Tabs#

Fitted tabs allow the tabs to expand and fit the width of a containing element.

Tab 1 is a long tab name because the server sent a long tab nameTab 2

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.

Tab 1Tab 2

Anatomy#

PropertyDefault tokenModifiable?
Tab label text
  • Always: $font-size-30, $font-weight-semibold, $line-height-20
  • Default: $color-text-weak, on hover: $color-text
  • Selected: $color-text-link
  • Disabled: $color-text-weaker
No
Tab Label box
  • border-bottom (selected tab): $color-border-primary
  • border-bottom (on hover): $color-border-primary-darker
  • Horizontal Tabs
    • padding-top: $space-40
    • padding-right: $space-20
    • padding-bottom: $space-40
    • padding-left: $space-20
    • margin-right: $space-70 (except for last tab)
  • Fitted Tabs
    • padding-top: $space-40
    • padding-right: $space-20
    • padding-bottom: $space-40
    • padding-left: $space-20
No
Tab List Border
  • Always: $color-border-light
No

Usage Guide#

API#

Installation#

yarn add @twilio-paste/tabs - or - yarn add @twilio-paste/core

Usage#

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.


Black lives matter.