Navigation rail
ExpressiveTop-level destinations along the start edge, collapsed or expanded, in medium windows.
import { NavigationRail, NavigationRailItem, useNavigationRail } from '@windmorph/react';Props
NavigationRail 16 props
Events
Text
Also accepts the root element's HTML attributes (id, data-*, event handlers).
NavigationRailItem 22 props
Events
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.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-nav-rail-collapsed-container-color | var(--md-sys-color-surface) | The collapsed rail. | NavigationRailCollapsedTokens.ContainerColor |
--md-comp-nav-rail-expanded-container-color | var(--md-sys-color-surface) | The expanded rail, beside the content. | NavigationRailExpandedTokens.ContainerColor |
--md-comp-nav-rail-expanded-modal-container-color | var(--md-sys-color-surface-container) | The modal expanded rail, over the content. | NavigationRailExpandedTokens.ModalContainerColor |
--md-comp-nav-rail-expanded-modal-container-shape | var(--md-sys-shape-corner-large) | The modal expanded rail's end corners. | NavigationRailExpandedTokens.ModalContainerShape |
--md-comp-nav-rail-item-active-indicator-color | var(--md-sys-color-secondary-container) | The current item's pill. | NavigationRailTokens.ItemActiveIndicatorColor |
--md-comp-nav-rail-item-active-icon-color | var(--md-sys-color-on-secondary-container) | The current item's icon. | NavigationRailTokens.ItemActiveIconColor |
--md-comp-nav-rail-item-inactive-icon-color | var(--md-sys-color-on-surface-variant) | The other items’ icons. | NavigationRailTokens.ItemInactiveIconColor |
--md-comp-nav-rail-item-active-label-text-color | var(--md-sys-color-secondary)Varies with layout. | The current item's label: `secondary` below its icon, `on-secondary-container` beside it (in the pill). | NavigationRailTokens.ItemActiveLabelTextColor |
--md-comp-nav-rail-item-inactive-label-text-color | var(--md-sys-color-on-surface-variant) | The other items’ labels. | NavigationRailTokens.ItemInactiveLabelTextColor |
Hooks
useNavigationRail
The rail around a component, for a custom destination that sits in a NavigationRail beside its items and changes with it. Throws outside a rail.
Returns NavigationRailState
Spec status
Built to the M3 Expressive navigation rail 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 |
|---|---|---|
| Collapsed navigation rail | Built | Variant · States, Inline |
| Expanded navigation rail | Built | Variant · Inline, States |
| Expanded layout: standard | Built | Configuration · Inline |
| Expanded layout: modal | Built | Configuration · Modal |
| Expanded behavior: hide when collapsed | Built | Configuration · Hide on collapse |
| With a menu and a FAB | Built | Use case · Inline |
| Badges, selected icons and disabled items | Built | Use case · States |
| Mode change motion | Differs | Items switch layout at once and the labels fade in at their new place, while the rail's width does the spring, instead of cross-fading each label as it slides. |
itemAlign="center" with a top header | Extension | Centres the items in the space below the header, which stays at the top, and an overflowing rail still scrolls to every item. |
onReselect | Extension | Runs when the current destination is pressed again, for resetting its scroll position to the top. |
--m3-rail-collapsed-width | Extension | A narrower collapsed rail, such as M3's 80px baseline, keeps the expand motion and every inset. |
indicatorMotion="slide" | Extension | Not in the M3 spec, where the active indicator expands from the centre of the icon: on the expanded rail the pill slides from the previous item on the fast spatial spring, as in Google's Expressive showcase. The collapsed rail always expands, and reduced motion fades the pill in place. |
| Navigation rail (baseline) | Not built | Not recommended in M3 Expressive; use the collapsed rail, or set --m3-rail-collapsed-width to 80px for its width. |
| Navigation drawer | Not built | Deprecated in M3 Expressive; use the expanded rail, modal for the modal drawer. |
Expanded layout: standard
BuiltConfiguration · Inline
Expanded layout: modal
BuiltConfiguration · Modal
Expanded behavior: hide when collapsed
BuiltConfiguration · Hide on collapse
With a menu and a FAB
BuiltUse case · Inline
Badges, selected icons and disabled items
BuiltUse case · States
Mode change motion
DiffersItems switch layout at once and the labels fade in at their new place, while the rail's width does the spring, instead of cross-fading each label as it slides.
ExtensionitemAlign="center"with a top headerCentres the items in the space below the header, which stays at the top, and an overflowing rail still scrolls to every item.
ExtensiononReselectRuns when the current destination is pressed again, for resetting its scroll position to the top.
Extension--m3-rail-collapsed-widthA narrower collapsed rail, such as M3's 80px baseline, keeps the expand motion and every inset.
ExtensionindicatorMotion="slide"Not in the M3 spec, where the active indicator expands from the centre of the icon: on the expanded rail the pill slides from the previous item on the fast spatial spring, as in Google's Expressive showcase. The collapsed rail always expands, and reduced motion fades the pill in place.
Navigation rail (baseline)
Not builtNot recommended in M3 Expressive; use the collapsed rail, or set
--m3-rail-collapsed-widthto 80px for its width.Navigation drawer
Not builtDeprecated in M3 Expressive; use the expanded rail,
modalfor the modal drawer.
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.
NavigationRail,NavigationRailItem: 29.6 kB
Differences from Compose
- The expanded width is the widest label plus 104px of item chrome, clamped to 220–360px, exposed as the
--m3-rail-widthvariable, so a consumerw-*class still wins. - As in Compose, the items' height and spacing spring with the rail's width (64 → 48px and 4 → 0px) and each icon moves to its new place on the default spatial spring. Where Compose cross-fades each label while sliding it, the labels fade in at their new place. Under reduced motion it all changes at once.
- The modal rail's sheet is portalled to the end of the page, so a token set inline on an element around the rail doesn't reach it. Set the
--md-comp-nav-rail-expanded-modal-*tokens on:rootor a theme, in a class on aThemeScope(overlays opened in it carry its class), or withclassNames.sheet. - The current destination is
aria-current="page", styled throughdata-current: it is the page the app is on, not a selection, so the prop iscurrent(selected, its name before 0.2.9, still works).