Panel 1
Open in Playroom
Tabs provides a horizontally arranged group of buttons that control the visibility of the associated tab panels.

Alternatives

  • Accordion For a vertical, expandable list of content sections.

Design considerations

The Tabs and TabPanels components can be positioned wherever you like, e.g. the tab panels can be nested within a Card while the tabs sit above the card.

Development considerations

All tab components must be nested within a TabsProvider which provides the state.Somewhere within TabsProvider you must:
  • Provide a Tabs component containing multiple Tab components.
  • Provide a TabsPanels component containing multiple TabPanel components.

Alignment

Tabs are left aligned by default, but this can be customised via the align prop on Tabs.
Panel 1
Open in Playroom

Increasing the divider width

In cases where you only have a couple of tabs, you may find that the tab strip lacks visual affordance. To address this, you can set the divider prop to “full” on the Tabs component.
Panel 1
Open in Playroom

Hiding the divider

If you’ve placed the tab strip and tab content on different backgrounds, the divider line is likely to be redundant visual noise. To hide it, you can set the divider prop to “none” on the Tabs component.
Panel 1
Open in Playroom

Gutters

Tabs are horizontally scrollable when they’re too wide to fit on screen. If you’d like to align the tabs with content below them (e.g. when the tab panels are inside a card but the tabs are outside), you can provide a gutter prop to Tabs that accepts a value from Braid’s space scale.
Panel 1
Open in Playroom

Badge support

Add a Badge alongside the Tab by using the badge prop.
Panel 1
Open in Playroom

Inserting an icon

For decoration or help distinguishing between tabs, an icon can be provided. This will be placed to the left of the label.
Panel 1
Open in Playroom

Size

Customise the size of the Tabs via the size prop, which accepts either standard or small.
Standard tabs
Small tabs
Open in Playroom

Reserve hit area

By default, a Tab will only occupy the vertical space from the top of the label to the active underline. This means the hit area will bleed out into the space above.The bleed can be disabled by setting the reserveHitArea prop to true.
Open in Playroom

State management

Tabs manage their own state by default. If you’d like to manage the state yourself, you must pass an item prop to each Tab and TabPanel element, as well as selectedItem and onChange props to TabsProvider.
Panel 2
Open in Playroom

Data attributes

Braid components are very explicit about the properties they accept, which makes providing arbitrary data attributes not possible. Instead, a data prop can be provided as a single collection of data attributes.
<TabsProvider>
  <Tabs
    data={{ testid: 'tabs-1' }}
    // => data-testid="tabs-1"
  >
    <Tab data={{ testid: 'tab-1' }}>
      ...
    </Tab>
  </Tabs>
  <TabPanels>
    <TabPanel data={{ testid: 'tab-panel-1' }}>
      ...
    </TabPanel>
  </TabPanels>
</TabsProvider>