Navigation rail
ExpressiveTop-level destinations along the start edge, collapsed or expanded, in medium windows.
import { NavigationRail, NavigationRailItem, useNavigationRail } from '@windmorph/react';Purpose
A navigation rail places a screen's top-level destinations along the start edge, for medium and larger windows. Collapsed it is 96px wide with the icon above each label; expanded it is 220–360px with the icon beside the label. Put a menu button in header to toggle expanded. A FAB in the header is an ExtendedFab given the rail's expanded, so it shows its label only while the rail is expanded, and elevation="flat", since a FAB nested in the rail rests at level 0 (M3). On compact windows use a NavigationBar instead.
The icons stay on one line through the middle of the collapsed rail in both states, so only the labels and the rail's edge move. For a narrower collapsed rail, such as M3's 80px baseline rail, set --m3-rail-collapsed-width (for example the class [--m3-rail-collapsed-width:80px]) rather than a w-* class: every inset follows it, and the rail still expands.
In the expanded rail the pill hugs its icon and label. In both states the new destination's pill expands from the centre of its icon on the default spatial spring, and its label turns bold. With indicatorMotion="slide", an extension beyond the spec, the expanded rail's pill slides from the previous destination instead. The whole row is the target. An item's currentIcon cross-fades with its icon. A long label wraps between words and the item grows taller; a single word too long for its item may break only where the browser hyphenates it for the page's lang, never bare, and a line it still overflows ends with an ellipsis. The accessible name is always the full label. While the rail widens, labels stay on one line, clipped by the rail, so no icon moves. A press ripples through the pill.
itemAlign="center" centres the items in the space below the header (M3 recommends it on tablets, where the middle is easier to reach); the header stays at the top. divider draws an outline-variant line on the edge next to the content. An item's badge (a Badge) sits on the icon while collapsed and after the label while expanded; onReselect runs when the current destination is pressed again. A FAB in the header should rest flat (level 0) in the rail.
Each NavigationRailItem is a link (href) or a button (onPress) with an icon, an optional currentIcon and a label. current marks the current destination. With modal the expanded rail opens over the page as a sheet with a scrim; hideOnCollapse hides the in-flow rail so only the sheet shows. With hideOnCollapse="compact" it hides only below 600px wide, in CSS, so one rail is the rail on larger windows and the drawer on a phone. useNavigationRail tells a custom destination whether it's in an expanded rail or the sheet, and closes the sheet.
When not to use
In compact windows use a Navigation bar; for in-page sections use Tabs.
See also
- Navigation rail on m3.material.io: Material's own guidelines, with anatomy and specs.
- Navigation bar: 3–5 destinations along the bottom of compact and medium windows, stacked or inline.
- Tabs: Primary and secondary tab rows with a sliding indicator, scrollable when they overflow.