---
title: Tabs
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Tabs } from '@telus-uds/components-web'
import { Tabs as BaseDocs } from 'docs/@telus-uds/components-base'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# Tabs

<LibraryInfo figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D3687%253A37696" />

```jsx live
function TabsExample() {
  const [value, setValue] = useState('one')

  return (
    <>
      <Tabs
        value={value}
        onChange={setValue}
        items={[
          { label: 'Tab one', id: 'one' },
          { label: 'Tab two', id: 'two' },
          { label: 'Tab three', id: 'three' },
          { label: 'Tab four', id: 'four' },
          { label: 'Tab five', id: 'five' }
        ]}
      />
      {value === 'one' && <Typography>Tab one content</Typography>}
      {value === 'two' && <Typography>Tab two content</Typography>}
      {value === 'three' && <Typography>Tab three content</Typography>}
      {value === 'four' && <Typography>Tab four content</Typography>}
      {value === 'five' && <Typography>Tab five content</Typography>}
    </>
  )
}
```

## Introduction

Use Tabs to display a horizontal menu of tabs that change the content shown below when pressed.

If there are too many tabs to fit the horizontal space, left and right buttons are shown.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

```jsx live
<Tabs
  items={[
    { label: 'Tab one', href: '#one', id: 'one' },
    { label: 'Tab two', href: '#two', id: 'two' },
    { label: 'Tab three', href: '#three', id: 'three' },
    { label: 'Tab four', href: '#four', id: 'four' },
    { label: 'Tab five', href: '#five', id: 'five' }
  ]}
/>
```

## Guidance

- Use Tabs to show/hide a mutually exclusive content areas.
- If the tabs should link to a wholly different page with its own URL, use `NavigationBar` instead
- Recommend to use labels that are 35 characters or fewer
- Allow the use of hashes in the URL to automatically load a tab. Eg. http://t.com#premium should load the “Premium” tab
- Change the page URL to include the hash as tabs change

### Accessibility

- If a user is using tabbed navigation and horizontal scrolling is required, tabbing through tabs scrolls them into view automatically
- Scrolling methods other than the scroll buttons may also be used, such as touchscreen swipes and touchpad or mousewheel scrolling
- Consider including an assertive focus effect inside content to move screenreader focus to the appropriate heading or content start when new content is rendered

### Controlled usage

Pass `value` and `onChange` to control the tabs from a parent. This is usually the easiest way to render different
content for different tabs:

- `value` should be the `id` property of the current tab in the `items` array
- `onChange` should be a function that updates the state that selects content and is passed to `value`
- To integrate with URL hashes on web so selections remain after returning to a page, choose the default state value based on the URL hash

### Platform considerations

<AvailableOnBoth />

Touch swipes with momentum may be used to scroll through many tabs, in addition to the scroll buttons.

Keep in mind that URL hashes won't have any effect in an app.

## Props

<PropsTable base={BaseDocs} />

## Tokens

<TokensTable
  base={BaseDocs}
  component="Tabs"
  tokensProps={['tokens', 'itemTokens', 'scrollButtonTokens']}
/>

## Variants

### Inverse

- Use on dark backgrounds.

```jsx live
<div style={{ backgroundColor: 'black', padding: 20 }}>
  <Tabs
    variant={{ inverse: true }}
    items={[
      { label: 'Tab one', href: '#one', id: 'one' },
      { label: 'A little bit longer Tab two', href: '#two', id: 'two' },
      { label: 'Tab three', href: '#three', id: 'three' },
      { label: 'Tab four', href: '#four', id: 'four' },
      { label: 'Tab five', href: '#five', id: 'five' }
    ]}
  />
</div>
```

### Equal Width

Divide all the available width equally among the tab items.
This variant is only available on the web.

```jsx live
<Tabs
  variant={{ equalWidth: true }}
  items={[
    { label: 'Tab one', href: '#one', id: 'one' },
    { label: 'A little bit longer Tab two', href: '#two', id: 'two' },
    { label: 'Tab three', href: '#three', id: 'three' },
    { label: 'Tab four', href: '#four', id: 'four' },
    { label: 'Tab five', href: '#five', id: 'five' }
  ]}
/>
```

### Dynamic Width

Though not exactly through a variant, but dynamic width, where every tab item can take necessary space to layout its content instead of wrapping, can be achieved by customizing the `maxWidth` token which applies to the tab item.
This customization is only available on the web.

```jsx live
<Tabs
  itemTokens={{
    maxWidth: 'none'
  }}
  items={[
    { label: 'Tab one', href: '#one', id: 'one' },
    { label: 'A little bit longer Tab two', href: '#two', id: 'two' },
    { label: 'Tab three', href: '#three', id: 'three' },
    { label: 'Tab four', href: '#four', id: 'four' },
    { label: 'Tab five', href: '#five', id: 'five' }
  ]}
/>
```

### Dropdown

Improve the accessibility and usability of `Tabs` by displaying as a dropdown element for xs and sm viewports.

```jsx live
<Tabs
  variant={{ dropdown: true }}
  items={[
    { label: 'Tab one', href: '#one', id: 'one' },
    { label: 'Tab two', href: '#two', id: 'two' },
    { label: 'Tab three', href: '#three', id: 'three' },
    { label: 'Tab four', href: '#four', id: 'four' },
    { label: 'Tab five', href: '#five', id: 'five' }
  ]}
/>
```

## Feedback

<Feedback component="Tabs" />
