---
title: NavigationBar
---

import LibraryInfo from '@theme/LibraryInfo'
import { ExternalCodeBlock, Feedback, TokensTable, PropsTable } from '../../src/components'
import { NavigationBar, StackView, Typography, ResponsiveImage } from '@telus-uds/components-web'
import { NavigationBar as WebDocs } from 'docs/@telus-uds/components-web'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# NavigationBar

<LibraryInfo
  packageType="Web Component"
  figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FTkOGIVaatADU8fDgNEA3GW%2FAllium-Community-Components-Work-in-Progress%3Fnode-id%3D498%253A2029"
/>

<ExternalCodeBlock
  file="navigation-bar-params"
  scope={{ NavigationBar, StackView, ResponsiveImage, Typography }}
/>

## Introduction

```jsx
import { NavigationBar } from '@telus-uds/components-web'
```

Use `NavigationBar` to allow customers to consistently navigate across a group of pages, such as key pages
within a specific product line.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

- Place `NavigationBar` directly under the main navigation whenever possible
- `NavigationBar` heading should carry the page's h1 tag (used by default whenever the `heading` prop is provided)
- `NavigationBar` converts to a dropdown in smaller screen sizes (M, S, & XS breakpoints)
- Item labels should not be full sentences or sales messaging
- It's recommended to use headings and labels that are 35 characters or fewer
- Be considerate of other languages & label lengths when writing
- It's advised to limit the number items to 7 in total
- Item dropdowns should have no more than 5 items
- `NavigationBar` should always live on a white background (ie. it should not blend into the content of the page)
- A grey/other colored background should be used for the element (e.g. hero or category banner) directly below the `NavigationBar`
- A page should use either a `NavigationBar` or an on-page navigation, not both
- The `items` array should be identical between each `NavigationBar` in each page
  in a set. Consider defining it in its own file and importing it into each appropriate page
- Provide a marketing/creative led headline in the hero banner; render as `<h2>`
- Avoid full sentences or sales messaging

### Controlled usage

Pass `value` and `onChange` to `NavigationBar` to control the selected content.

- `value` should be the `id` property of the current tab in the `items` array
- `onChange` should be a function that updates the state that selects content and is passed to `value`

```jsx live
function NavigationBarControlledExample() {
  const [value, setValue] = useState('3.2')

  return (
    <>
      <NavigationBar
        heading="Title for whole section"
        value={value}
        onChange={setValue}
        items={[
          {
            id: '1',
            label: 'Page in section',
            href: '#introduction'
          },
          {
            id: '2',
            label: 'Another page',
            href: '#guidance'
          },
          {
            id: '3',
            label: 'Group of pages',
            onClick: (event) => console.log('Click event', event),
            items: [
              {
                id: '3.1',
                label: 'Page in group',
                href: '#props'
              },
              {
                id: '3.2',
                label: 'Another in group',
                href: '#tokens'
              }
            ]
          }
        ]}
      />

      <Spacer space={11} />
      <Spacer space={{ xs: 11, lg: 0 }} />
    </>
  )
}
```

### Accessibility

`NavigationBar` is designed to be accessible to users navigating by keyboard:

- Pressing "space" or "enter" keys open and close dropdown menus while their control button is focused.
- Items within a dropdown menu are focused next on pressing the "tab" key.
- After tabbing through the dropdown menu, focus goes to the next item in the main menu.
- Pressing "esc" key while any dropdown menu item is focused closes the dropdown menu.

### Platform considerations

<AvailableOnWebOnly />

For a similar navigation pattern in native apps, use `Tabs` with an appropriate navigation function passed to its `onChange` prop.

## Props

<PropsTable web={WebDocs} />

## Tokens

These tokens are applied to the individual objects of `items` array which is passed as prop to `NavigationBar` component.

<TokensTable web={WebDocs.Item} component="NavigationBar" />

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="NavigationBar" />
