Tabs
Primary and secondary tab rows with a sliding indicator, scrollable when they overflow.
import { Tabs, Tab } from '@windmorph/react';Props
Tabs 22 props
Tabelements.The selected tab's
key(controlled).The tab selected at first, when uncontrolled.
Disables every tab (
disabledKeysdisables some).The keys of tabs that can't be selected. They stay focusable, so keyboard and screen reader users find them (WAI-ARIA APG).
primarytabs sit below the top app bar and switch the page's main content;secondarytabs switch content within one section.Tabs keep their natural width (at least 90px) and the row scrolls.
Icons above the label (64px tabs) or before it (48px).
Web density,
0to-3, for the tab row (not the panels): each step takes 4px off the tabs (48px at 0, 36px at -3; 64px to 52px with icons above). Left out, the tabs take the density of the nearestThemeProviderorThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.Fixed tabs:
stretchfills the row;startandcentermake every tab as wide as the widest and place the group at the leading edge or the centre (M3's layout for wide windows). Ignored whenscrollable.A horizontal swipe on the panel selects the next or previous tab (mirrored in RTL), as M3 tabs do. Vertical gestures still scroll. Avoid it when the panel holds swipeable content such as a map or a carousel.
manual: the arrow keys move focus and Space / Enter selects the focused tab, the M3 keyboard pattern.automaticselects on focus.Ref to the root
<div>element.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The outer container, merged with
className.The row's scrolling box around
list(it carries the row's surface when aligned).The row of tabs (
role="tablist").Every tab.
Each tab's icon.
Each tab's label.
The active indicator under the selected tab.
The selected tab's panel.
The element's unique identifier. See MDN.
Defines a string value that labels the current element.
Identifies the element (or elements) that labels the current element.
Identifies the element (or elements) that describes the object.
Identifies the element (or elements) that provide a detailed, extended description for the object.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tab 6 props
The tab's label. Optional for icon-only tabs, which then need
aria-label.Icon above (or before) the label. Hidden from assistive tech.
The panel shown while this tab is selected. Leave it out for tabs that only navigate.
Plain-text label when
titleis not a string.A
Badgefor news in this tab (at most four characters, "+" included). It sits on a stacked icon, otherwise 4px after the label, and describes the tab to assistive tech.
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
| Primary (variant) | |||
--md-comp-primary-navigation-tab-container-color | var(--md-sys-color-surface) | The tab row. | PrimaryNavigationTabTokens.ContainerColor |
--md-comp-primary-navigation-tab-divider-color | var(--md-sys-color-outline-variant) | The 1px divider along the row's bottom edge. | PrimaryNavigationTabTokens.DividerColor |
--md-comp-primary-navigation-tab-active-indicator-color | var(--md-sys-color-primary) | The selected tab's indicator. | PrimaryNavigationTabTokens.ActiveIndicatorColor |
--md-comp-primary-navigation-tab-with-icon-active-icon-color | var(--md-sys-color-primary) | The selected tab's icon. | PrimaryNavigationTabTokens.ActiveIconColor |
--md-comp-primary-navigation-tab-with-icon-inactive-icon-color | var(--md-sys-color-on-surface-variant) | An unselected tab’s icon, at rest. | PrimaryNavigationTabTokens.InactiveIconColor |
--md-comp-primary-navigation-tab-with-label-text-active-label-text-color | var(--md-sys-color-primary) | The selected tab's label. | PrimaryNavigationTabTokens.ActiveLabelTextColor |
--md-comp-primary-navigation-tab-with-label-text-inactive-label-text-color | var(--md-sys-color-on-surface-variant) | An unselected tab’s label, at rest. | PrimaryNavigationTabTokens.InactiveLabelTextColor |
| Secondary (variant) | |||
--md-comp-secondary-navigation-tab-container-color | var(--md-sys-color-surface) | The tab row. | SecondaryNavigationTabTokens.ContainerColor |
--md-comp-secondary-navigation-tab-divider-color | var(--md-sys-color-outline-variant) | The 1px divider along the row's bottom edge. | SecondaryNavigationTabTokens.DividerColor |
--md-comp-secondary-navigation-tab-active-indicator-color | var(--md-sys-color-primary) | The selected tab's indicator. | SecondaryNavigationTabTokens.ActiveIndicatorColor |
--md-comp-secondary-navigation-tab-with-icon-active-icon-color | var(--md-sys-color-on-surface) | The selected tab's icon. | SecondaryNavigationTabTokens.ActiveIconColor |
--md-comp-secondary-navigation-tab-with-icon-inactive-icon-color | var(--md-sys-color-on-surface-variant) | An unselected tab’s icon, at rest. | SecondaryNavigationTabTokens.InactiveIconColor |
--md-comp-secondary-navigation-tab-active-label-text-color | var(--md-sys-color-on-surface) | The selected tab's label. | SecondaryNavigationTabTokens.ActiveLabelTextColor |
--md-comp-secondary-navigation-tab-inactive-label-text-color | var(--md-sys-color-on-surface-variant) | An unselected tab’s label, at rest. | SecondaryNavigationTabTokens.InactiveLabelTextColor |
Spec status
Built to the M3 Expressive tabs spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Primary tabs | Built | Variant · Primary |
| Secondary tabs | Built | Variant · Secondary |
| Scrollable tabs | Built | Configuration · Scrollable |
| Icon and label text | Built | Configuration · Primary |
| Label text only | Built | Configuration · Secondary |
| Badges | Built | Configuration · Badges |
| Fixed tabs aligned to the centre or leading edge | Built | Use case · Badges |
| Swipe between fixed tabs | Built | Use case · Badges |
| Density (web, chosen by the reader) | Built | Use case · Density |
keyboardActivation="automatic" | Extension | Selects a tab as focus reaches it; the default is the spec’s manual activation, with Space or Enter. |
Primary tabs
BuiltVariant · Primary
Secondary tabs
BuiltVariant · Secondary
Scrollable tabs
BuiltConfiguration · Scrollable
Icon and label text
BuiltConfiguration · Primary
Label text only
BuiltConfiguration · Secondary
Badges
BuiltConfiguration · Badges
Fixed tabs aligned to the centre or leading edge
BuiltUse case · Badges
Swipe between fixed tabs
BuiltUse case · Badges
Density (web, chosen by the reader)
BuiltUse case · Density
ExtensionkeyboardActivation="automatic"Selects a tab as focus reaches it; the default is the spec’s manual activation, with Space or Enter.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Tabs,Tab: 22.1 kB
M3 Expressive specs
- Variants
primary, secondary
Differences from Compose
- The
primaryindicator slides on the default spatial spring when the selection changes; on first paint and when the row or the selected tab's content resizes (a web font loading) it moves into place at once. Primary tabs draw it 3px high with only its top corners rounded, as wide as the content (at least 24px); secondary tabs draw it 2px high across the whole tab (m3.material.io's measurements; Compose rounds every corner and uses 3px for both). The spec also says primary indicators are "inset 2dp on each side"; like Compose, the indicator is as wide as the tab's content (its label, or its icon when there is none), which already sits inside the tab's 16px padding, rather than 4px narrower. - Where Compose defaults an unselected tab's colour to the selected one, the token colours are used (labels
on-surface-variant, andon-surfaceon hover, focus or press). - A scrollable row animates the selected tab to the centre on the default spatial spring.
- React Aria takes arrow-key direction from its locale, so Tabs reads its laid-out direction and supplies a matching
I18nProviderlocale for correct RTL behaviour.