Skip to content

Tabs

Primary and secondary tab rows with a sliding indicator, scrollable when they overflow.

import { Tabs, Tab } from '@windmorph/react';

Props

By name or description, across the 28 props below

Tabs 22 props

  • childrentype ReactNodeRequired

    Tab elements.

  • valuetype Key | null

    The selected tab's key (controlled).

  • defaultValuetype Keydefault the first enabled tab

    The tab selected at first, when uncontrolled.

  • disabledtype booleandefault false

    Disables every tab (disabledKeys disables some).

  • disabledKeystype Iterable<Key>

    The keys of tabs that can't be selected. They stay focusable, so keyboard and screen reader users find them (WAI-ARIA APG).

  • varianttype "primary" | "secondary"default "primary"

    primary tabs sit below the top app bar and switch the page's main content; secondary tabs switch content within one section.

  • scrollabletype booleandefault false

    Tabs keep their natural width (at least 90px) and the row scrolls.

  • iconPlacementtype "start" | "top"default "top"

    Icons above the label (64px tabs) or before it (48px).

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider or ThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.

  • aligntype "stretch" | "start" | "center"default "stretch"

    Fixed tabs: stretch fills the row; start and center make 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 when scrollable.

  • swipeabletype booleandefault false

    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.

  • keyboardActivationtype "manual" | "automatic"default "manual"

    manual: the arrow keys move focus and Space / Enter selects the focused tab, the M3 keyboard pattern. automatic selects on focus.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

Events

  • onChangetype ((key: Key) => void)

    Called with the newly selected tab's key.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Tab 6 props

  • titletype ReactNode

    The tab's label. Optional for icon-only tabs, which then need aria-label.

  • icontype ReactNode

    Icon above (or before) the label. Hidden from assistive tech.

  • childrentype ReactNode

    The panel shown while this tab is selected. Leave it out for tabs that only navigate.

  • textValuetype string

    Plain-text label when title is not a string.

  • badgetype ReactElement<BadgeProps, string | JSXElementConstructor<any>>

    A Badge for 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.

Text

  • aria-labeltype string

    Accessible name for the tab. Required for icon-only tabs, which have no title.

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.

Tabs tokens (md-comp-tabs)
VariableDefaultPaintsCompose
Primary (variant)
--md-comp-primary-navigation-tab-container-colorvar(--md-sys-color-surface)The tab row.PrimaryNavigationTabTokens.ContainerColor
--md-comp-primary-navigation-tab-divider-colorvar(--md-sys-color-outline-variant)The 1px divider along the row's bottom edge.PrimaryNavigationTabTokens.DividerColor
--md-comp-primary-navigation-tab-active-indicator-colorvar(--md-sys-color-primary)The selected tab's indicator.PrimaryNavigationTabTokens.ActiveIndicatorColor
--md-comp-primary-navigation-tab-with-icon-active-icon-colorvar(--md-sys-color-primary)The selected tab's icon.PrimaryNavigationTabTokens.ActiveIconColor
--md-comp-primary-navigation-tab-with-icon-inactive-icon-colorvar(--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-colorvar(--md-sys-color-primary)The selected tab's label.PrimaryNavigationTabTokens.ActiveLabelTextColor
--md-comp-primary-navigation-tab-with-label-text-inactive-label-text-colorvar(--md-sys-color-on-surface-variant)An unselected tab’s label, at rest.PrimaryNavigationTabTokens.InactiveLabelTextColor
Secondary (variant)
--md-comp-secondary-navigation-tab-container-colorvar(--md-sys-color-surface)The tab row.SecondaryNavigationTabTokens.ContainerColor
--md-comp-secondary-navigation-tab-divider-colorvar(--md-sys-color-outline-variant)The 1px divider along the row's bottom edge.SecondaryNavigationTabTokens.DividerColor
--md-comp-secondary-navigation-tab-active-indicator-colorvar(--md-sys-color-primary)The selected tab's indicator.SecondaryNavigationTabTokens.ActiveIndicatorColor
--md-comp-secondary-navigation-tab-with-icon-active-icon-colorvar(--md-sys-color-on-surface)The selected tab's icon.SecondaryNavigationTabTokens.ActiveIconColor
--md-comp-secondary-navigation-tab-with-icon-inactive-icon-colorvar(--md-sys-color-on-surface-variant)An unselected tab’s icon, at rest.SecondaryNavigationTabTokens.InactiveIconColor
--md-comp-secondary-navigation-tab-active-label-text-colorvar(--md-sys-color-on-surface)The selected tab's label.SecondaryNavigationTabTokens.ActiveLabelTextColor
--md-comp-secondary-navigation-tab-inactive-label-text-colorvar(--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.

  • 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.

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 primary indicator 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, and on-surface on 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 I18nProvider locale for correct RTL behaviour.