Navigation
Navigation bar
The navigation bar is the row of three to five destinations at the bottom of a phone screen; use it to move between a product's top-level sections.
In kanso-ui as NavigationBar
Web and native
NavigationBar in kanso-ui 0.59.0, for React.
import { NavigationBar } from '@kanso-labs/kanso-ui'The bar of three to five top-level destinations that a compact window keeps along its bottom edge.
It follows Material Design's flexible navigation bar: 64px tall on the surface-container colour. Below the medium breakpoint (600px) each destination stacks its label under its icon and the destinations share the width equally; from there up each is a horizontal pill as wide as its content, grouped in the centre. When the horizontal labels would not fit whole, the bar keeps the vertical form until it is wide enough. The 8px between horizontal pills is the library's own, since the spec gives none.
What you provide
aria-label: the bar is a<nav>, and a page usually has more than one navigation landmark, so name it.- Three to five
NavigationBar.Itemchildren, each with anhref, aniconand its label as children. selectedRoute: the current route. The item whosehrefmatches gets the active indicator andaria-current="page".- Each destination is a React Aria
Link, so it routes through the app'sRouterProviderwhen there is one.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
selectedRoute | string | — | The route of the current destination, matched exactly against each destination's `href`. The match carries `aria-current="page"` and the active indicator. For a route nested under a destination, which no `href` matches whole, mark that destination with its own `isCurrent`. |
Also takes the props of RenderComponentProps<'nav'>.
Parts
NavigationBar.Item
href(required): where it goes, and whatselectedRouteis matched against.icon(required): the destination's icon, drawn at 24px.children(required): the label.badge:truefor a small dot, or a number for a large badge on the icon.badgeLabel: what the badge says, in words and in the reader's language ("3 new", or "new" for the dot). It follows the label in the item's accessible name, and is read only while the badge is drawn.isCurrent: marks the item current in place of theselectedRoutematch, for a route nested under it (/first/42under/first);falseturns the match off.- A label that does not fit is truncated with room between neighbours, and its full text is in the accessible name.
- Accepts React Aria
Linkprops otherwise;classNameandstylemay be functions of its render state.
Example
import { NavigationBar } from '@kanso-labs/kanso-ui'
<NavigationBar aria-label="Label" selectedRoute="/first">
<NavigationBar.Item href="/first" icon={<FirstIcon />}>First item</NavigationBar.Item>
<NavigationBar.Item href="/second" icon={<SecondIcon />} badge={3}
aria-label="Second item, 3 new">Second item</NavigationBar.Item>
<NavigationBar.Item href="/third" icon={<ThirdIcon />}>Third item</NavigationBar.Item>
</NavigationBar>The design’s classes
k-navbar, k-navbar__item, k-navbar__pill, k-icon and k-icon--fill, plus the --k-nav-count property for three or four destinations. In kanso-ui and react-native-kanso-ui it is NavigationBar.