Navigation
Tabs
Tabs switch between views of one thing without leaving the page, such as the payments, members and settings of a project.
In kanso-ui as Tabs
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.Listholding oneTabs.Tabper tab, each with anid. - A
Tabs.Panelper tab with the sameid, or none at all for a strip. - Selection is React Aria's:
defaultSelectedKey, orselectedKeywithonSelectionChange. - 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
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | |
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'sTabList.Tabs.Panel: the content for the tab with the sameid.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 inemtakes its size from the slot.badge:truefor 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.