Skip to content

Navigation bar

Expressive

3–5 destinations along the bottom of compact and medium windows, stacked or inline.

import { NavigationBar, NavigationBarItem } from '@windmorph/react';

Props

By name or description, across the 33 props below

NavigationBar 11 props

  • childrentype ReactNodeRequired

    NavigationBarItem elements (3–5 in M3).

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

    Icons above labels (compact windows) or beside them (the flexible bar in medium windows). Items beside their icons stack, sharing the width equally, whenever their labels don't fit on one line side by side (a narrow bar or large text), so no label is cut off; the bar then carries data-stacked.

  • arrangementtype "equal" | "centered"default "equal", or "centered" when iconPlacement is "start"

    Share the width equally, or centre the items. Stacked items centre within side padding; items beside their icons keep their own width, with the extra space at the ends.

  • scrollBehaviortype "pinned" | "hide-on-scroll"default "pinned"

    hide-on-scroll slides the bar off the bottom while the page scrolls down and back on any scroll up. The bar becomes sticky at the bottom, so put it last in a scrolling layout and don't add positioning classes. It stays put under reduced motion. M3: don't hide the bar on scroll when a screen reader is active, so leave this off where assistive tech is in use.

  • scrollReftype RefObject<HTMLElement | null>

    With hide-on-scroll, the element that scrolls instead of the page.

  • reftype Ref<HTMLElement>

    Ref to the root element.

Text

  • aria-labeltype string

    Accessible name for the navigation bar. Required unless aria-labelledby is set.

  • aria-labelledbytype string

    The id of the element that names the navigation bar. Required unless aria-label is set.

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

NavigationBarItem 22 props

  • icontype ReactElement<unknown, string | JSXElementConstructor<any>>Required

    The icon. Hidden from assistive tech; the label names the item.

  • childrentype ReactNodeRequired

    The label.

  • currentIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon shown while the item is the current destination, e.g. a filled variant.

  • currenttype booleandefault false

    Marks the current destination (aria-current="page"): the page the app is on, which the item shows with its active indicator.

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

    A Badge for dynamic information, such as a count. It overlaps the icon's top end, or sits after the label in the expanded rail. It describes the item to assistive tech with its text, or with badgeLabel.

  • badgeLabeltype string

    What the badge means, read after the item's name, e.g. "3 new messages". Defaults to the badge's label or text; a small (dot) badge reads its labels.newNotification ("New notification"), as M3 asks of badges without a count.

  • reftype Ref<HTMLButtonElement> | Ref<HTMLAnchorElement>

    Ref to the root element: the <button>, or the <a> with href.

  • disabledtype booleandefault false

    Disables the element: it can't be pressed or focused, and shows the disabled style.

  • valuetype string | number | readonly string[]

    The value a submit button sends with its form, under its name. On a toggle (toggle) it's a string naming the button in a selection group instead, required to take part in the group's selection.

  • draggedtype booleandefault false

    The element is being dragged (e.g. a card picked up to move it): sets data-dragged for the dragged state layer. A consumer's own data-dragged attribute counts too.

  • preventFocusOnPresstype booleandefault false

    Don't move focus to the element on press (set by menu triggers).

  • astype "button"default "button"

    The element rendered: a native <button>.

  • hreftype string

    Renders a link. Navigation goes through React Aria's RouterProvider when one is set.

Events

  • onReselecttype (() => void)

    Called when the current destination is pressed again. M3: re-selecting the active destination resets the page's scroll position to the top, so scroll to the top here.

Also accepts every <a> or <button> attribute.

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.

Navigation bar tokens (md-comp-nav-bar)
VariableDefaultPaintsCompose
--md-comp-nav-bar-container-colorvar(--md-sys-color-surface-container)The bar.NavigationBarTokens.ContainerColor
--md-comp-nav-bar-item-active-indicator-colorvar(--md-sys-color-secondary-container)The current item's pill.NavigationBarTokens.ItemActiveIndicatorColor
--md-comp-nav-bar-item-active-icon-colorvar(--md-sys-color-on-secondary-container)The current item's icon.NavigationBarTokens.ItemActiveIconColor
--md-comp-nav-bar-item-inactive-icon-colorvar(--md-sys-color-on-surface-variant)The other items’ icons.NavigationBarTokens.ItemInactiveIconColor
--md-comp-nav-bar-item-active-label-text-colorvar(--md-sys-color-secondary)Varies with layout.The current item's label: `secondary` below its icon, `on-secondary-container` beside it (in the pill).NavigationBarTokens.ItemActiveLabelTextColor
--md-comp-nav-bar-item-inactive-label-text-colorvar(--md-sys-color-on-surface-variant)The other items’ labels.NavigationBarTokens.ItemInactiveLabelTextColor

Spec status

Built to the M3 Expressive navigation bar 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.

  • Flexible navigation bar

    Built

    Variant · Stacked, Inline

  • Navigation item layout: vertical

    Built

    Configuration · Stacked

  • Navigation item layout: horizontal (medium windows)

    Built

    Configuration · Inline

  • Badges on destinations

    Built

    Use case · Stacked

  • Hide on scroll

    Built

    Use case · Hide on scroll

  • arrangement

    Extension

    Shares the width equally or centres the items, for either item layout (Compose's ShortNavigationBarArrangement).

  • onReselect

    Extension

    Runs when the current destination is pressed again, for resetting its scroll position to the top.

  • Navigation bar (baseline)

    Not built

    Deprecated in M3 Expressive; the flexible bar replaces it.

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.

  • NavigationBar, NavigationBarItem: 24.8 kB

Differences from Compose

  • This is Compose's short / flexible navigation bar (ShortNavigationBar), which replaces the original navigation bar; it is at least 64px surface-container with no elevation.
  • arrangement="centered" reproduces Compose's side padding of (100% − 10% × (n + 3)) / 2 for up to 6 stacked items. Inline items are sized to their content, 8px apart (a provisional gap; the spec gives no value).
  • The pill grows from its centre on the default spatial spring, and the state layer and focus ring are pill-shaped, as in Compose's indicator ripple: a press ripples through the pill from the press point. Items fill the bar's height, so the whole 64px is the touch target and inline pills sit in its middle.