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.Item children, each with an href, an icon and its label as children.
  • selectedRoute: the current route. The item whose href matches gets the active indicator and aria-current="page".
  • Each destination is a React Aria Link, so it routes through the app's RouterProvider when there is one.

Props

PropTypeDefaultDescription
selectedRoutestring—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

  • href (required): where it goes, and what selectedRoute is matched against.
  • icon (required): the destination's icon, drawn at 24px.
  • children (required): the label.
  • badge: true for 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 the selectedRoute match, for a route nested under it (/first/42 under /first); false turns 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 Link props otherwise; className and style may 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.