Web and native

Tabs in kanso-ui 0.59.0, for React.

import { Tabs } from '@kanso-labs/kanso-ui'

A tab bar and the panels it switches between, built from Tabs.List, Tabs.Tab and Tabs.Panel.

It follows Material Design's primary and secondary tabs: a 48px bar on the surface, divided into equal sections over a 1px outline-variant divider. A primary tab given an icon stacks it over the label and the bar grows to 64px. The spec draws no vertical tabs, so orientation="vertical" turns the horizontal bar's own measurements on their side, with the divider and the indicator along the bar's inline end.

What you provide

  • A Tabs.List holding one Tabs.Tab per tab, each with an id.
  • A Tabs.Panel per tab with the same id, or none at all for a strip.
  • Selection is React Aria's: defaultSelectedKey, or selectedKey with onSelectionChange.
  • Each tab's label is its accessible name. A tab carrying a badge should say what the badge says in its aria-label ("Second item, 3 new").

Props

PropTypeDefaultDescription
childrenReactNode—
layout'fixed' | 'scrollable''fixed'How the bar shares its room: `fixed` divides it into equal sections, and `scrollable` gives each tab its label's width in a bar that scrolls, which is the page's choice for more tabs than the room has sections for.
variant'primary' | 'secondary''primary'Which of the page's two tab bars this is: `primary` for the main one, `secondary` for a strip under a primary one.

Also takes the props of Omit<TabsProps$1, 'children'>.

Parts

  • Tabs.List: the bar itself, React Aria's TabList.
  • Tabs.Panel: the content for the tab with the same id.
  • Tabs.Panels: an optional box around the panels that animates its height as one panel gives way to another.

Tabs.Tab

  • id: links it to its panel and is the key selection reports.
  • icon: a 24px icon, over the label on a primary tab, before it on a secondary one. An icon drawn in em takes its size from the slot.
  • badge: true for a small dot, or a number for a large badge. It sits on a primary tab's icon and after the label elsewhere.
  • isDisabled: announced as disabled and cannot be activated, though the arrow keys still reach it.
  • href: renders the tab as a link.

A long label wraps onto a second line, then ends in an ellipsis.

Example

import { Tabs } from '@kanso-labs/kanso-ui'
<Tabs defaultSelectedKey="first">
  <Tabs.List aria-label="Label">
    <Tabs.Tab id="first">First item</Tabs.Tab>
    <Tabs.Tab id="second">Second item</Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel id="first">The first panel.</Tabs.Panel>
  <Tabs.Panel id="second">The second panel.</Tabs.Panel>
</Tabs>

The design’s classes

k-tabs on the tab list and k-tab on each tab; the selected look follows aria-selected="true". Until bundle.css has it, the preview gives k-tabs room for the focus ring and draws the hairline as a background, so the indicator no longer overflows into a scrollbar. In kanso-ui and react-native-kanso-ui it is Tabs.