Skip to main content

NavMenu

Used to display a navigation menu with links and dropdowns.

Submit feedback
github

Migration Information

For teams migrating from the V1 to V2 component, please refer to the migration guide for changes to the component.
Component Guide
import { NavMenu } from '@uhg-abyss/web/ui/NavMenu';

Overview

The NavMenu component is a navigation menu that can contain links and dropdowns. It is designed to be accessible and customizable, allowing for a variety of use cases. Please follow the examples below for proper implementation of all the available NavMenu subcomponents.

The NavMenu.Root is the provider component that contains all NavMenu subcomponents and accepts the following props:

  • hasOverlay is used to show or hide the overlay when a dropdown menu is opened. The default value is false.

  • zIndex provides the ability to set the z-index value of the navigation menu. If hasOverlay is utilized, it will also adjust the z-index of the overlay and can assist with managing placement when multiple navigation menus are used on a single page. The default value is 101.

  • enableOutsideScroll is used to allow the user to scroll, even when a navigation dropdown item is open. The default value is false.

  • sticky provides the ability to position the navigation menu at the top of the viewport.

  • mobileDrawer is used to render the navigation menu in a drawer instead of a dropdown on mobile screen sizes. The default value is true.

Position viewport to trigger

Add the optional positionViewportToTrigger prop to NavMenu.Root in order to position the dropdown menu viewport with the corresponding trigger element. positionViewportToTrigger also takes in an optional minWidth property to set the minimum width of the viewport. The default min-width is 350px.

If not utilized, the default behavior will occur and the dropdown menu will span a majority of the width of the navigation menu bar.

The NavMenu.List component is a wrapper for the top level menu items and should contain NavMenu.Link or NavMenu.Item as direct children.

The NavMenu.Link component is used to create a link or button in the top-level navigation menu and is a direct child of NavMenu.List. To use as a link, provide a valid value to the href prop. To use as a button, utilize the onClick prop instead.

Selected

Use the selected prop to signal that a given item refers to the current path the user is on. This can be used on a NavMenu.Link or a NavMenu.Trigger.

Use the following components to add a dropdown menu to the top level navigation menu.

The NavMenu.Item component is the parent component for creating a dropdown menu item. As direct children, it should contain a trigger with content combination through usage of NavMenu.Trigger and NavMenu.Content. It is a direct child of NavMenu.List.

The NavMenu.Divider is a simple divider line component that allows you to add a visual separator between different NavMenu.Item components.

The NavMenu.Trigger component is a button element that toggles viewing of the dropdown menu content.

Use the following components to construct the content for the dropdown menu.

The NavMenu.Content component is used to wrap the dropdown menu content and should be a direct child of NavMenu.Item. Please see the following subcomponents below for constructing your dropdown menu content.

This component should be the outermost component of what is passed into content. It is used to provide styling for the dropdown container and the columns that go inside it.

This component should be a child of NavMenu.Columns. Each column that is a child of NavMenu.Columns will be a distinct column in the dropdown menu.

The children of this component will be displayed vertically; you can use NavMenu.MenuItem as children to auto-format and style your input, or pass in your own custom renders to be displayed within the column.

Available NavMenu.Column props:

  • title: Displays a bolded header as an <h2> at top of the column.
  • href: Converts a column header into a link.
  • onClick: Converts a column header into a button. It takes in a function that will be called when clicked.

This component should be a child of NavMenu.Column. Use this component to automatically style links/buttons in your dropdown that only have a title, description, and link/button action.

Available NavMenu.MenuItem props:

  • title: The title of the item.
  • description: The description of the item.
  • href: Converts the item into a link (on external links, an icon will appear next to the title to signify that it will open in a new window).
  • onClick: Converts the item into a button. It takes in a function that will be called when clicked.

NOTE: Each NavMenu.MenuItem should have an href or onClick, but not both.

The NavMenu.MenuItemUnstyled component is an unstyled wrapper that ensures proper menu closing behavior when using custom interactive elements.

Use this component when you need to include your own custom-styled buttons or links in the navigation menu while maintaining the automatic menu closure on click that the standard MenuItem provides.

StateRouter

The StateRouter component is used to manage the routing within the dropdown menu. It allows for nested routes and provides a way to navigate between different sets of dropdown menu content.

NavMenu.Root Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The child components of NavigationMenu.Root
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
enableOutsideScroll
boolean
false
-
Allows scrolling outside the NavMenu even when a NavMenu dropdown item is open
hasOverlay
boolean
false
-
Show overlay when set to true
maxNavWidth
string | number
'1088px'
-
Set the maximum width of the NavMenu
mobileDrawer
boolean
true
-
Use a Drawer view on mobile screen sizes
position
"center" | "end" | "start"
'start'
-
Set the position of the menu items
positionViewportToTrigger
boolean | { minWidth?: string | number | undefined; }
false
-
Position and configure the dropdown menu viewport with the corresponding trigger element
removeScrollProps
IRemoveScrollProps & React.RefAttributes<HTMLElement>
--
Props to manage remove scroll usage when enableOutsideScroll is not utilized
sticky
boolean | React.CSSProperties
false
-
Make the navigation menu sticky at the top of the viewport, or pass on your own custom css properties.
viewportHeight
number | null
'null'
-
Determines the height of the viewport
zIndex
number
101
-
Set the z-index of the NavMenu

Below are the link(s) to the relevant GitHub type files:

NavMenu.List Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The child components of NavigationMenu.List
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Item Props

NameTypeDefaultRequiredDescription
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Link Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The children of the menu link.
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
href
string | undefined
--
The href of the menu link.
inStateRouter
boolean
--
Whether the menu link is in the state router.
onClick
(event: React.MouseEvent<HTMLElement, MouseEvent>) => void
--
The onClick handler for the menu link.
routerComponent
React.ComponentType<any>
--
Custom router component to use for client-side navigation
(e.g., Next.js Link, Gatsby Link, etc.)
selected
boolean
--
Whether the menu link is selected.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Trigger Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The children of the menu trigger.
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
onClick
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void
--
The onClick handler for the menu trigger.
selected
boolean
--
Whether the menu trigger is selected.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Column Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
'null'
The children of the column.
className
string
--
CSS class name to apply to each element within the component
columnCount
number | null
'null'
-
The number of columns in the parent container.
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
hideIcon
boolean
false
-
Whether to hide the external link icon.
href
string | undefined
'null'
-
The href of the column.
onClick
(event: React.MouseEvent<HTMLElement, MouseEvent>) => void
'null'
-
The function to call when the column is clicked.
routerComponent
React.ComponentType<any>
--
Custom router component to use for client-side navigation
(e.g., Next.js Link, Gatsby Link, etc.)
title
React.ReactNode
'null'
-
The title of the column.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Columns Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The children of the columns.
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.

Below are the link(s) to the relevant GitHub type files:

NavMenu.MenuItem Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
'null'
-
The child components of NavigationMenuItem
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
description
React.ReactNode
'null'
-
The description of the menu item.
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
hideIcon
boolean
false
-
Whether to hide the external link icon.
href
string | undefined
'null'
-
The href of the menu item.
onClick
(event: React.MouseEvent<HTMLElement, MouseEvent>) => void
'null'
-
The function to call when the menu item is clicked.
routerComponent
React.ComponentType<any>
--
Custom router component to use for client-side navigation
(e.g., Next.js Link, Gatsby Link, etc.)
title
React.ReactNode
'null'
The title of the menu item.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Content Props

NameTypeDefaultRequiredDescription
children
React.ReactNode
-
The content of NavigationMenu.Content
className
string
--
CSS class name to apply to each element within the component
css
Abyss.CSSProperties | Partial<Record<`abyss-${T}`, Abyss.CSSProperties>>
--
Object containing CSS styling to apply; uses the classes listed in the "Integration" tab of the component's documentation

See CSS Prop Styling for more information
data-testid
string
--
Suffix used to create a unique ID used for automated testing

See Component Testing for more information
disableDefaultProviderProps
boolean
false
-
If set to true, the component will not use the DefaultPropsProvider values.

If you aren’t using the DefaultPropsProvider, this prop can be ignored.
onInteractOutside
(event: CustomEvent<{ originalEvent: PointerEvent | FocusEvent; }>) => void
--
A callback fired when interaction (pointer or focus event) happens outside the bounds of the component
onPointerDownOutside
(event: CustomEvent<{ originalEvent: PointerEvent; }>) => void
--
A callback fired when the pointer is down outside the content.

Below are the link(s) to the relevant GitHub type files:

NavMenu.Root Classes

Class NameDescription
.abyss-nav-menu-portalThe portal element of the NavMenu
.abyss-nav-menu-overlayThe overlay element of the NavMenu
.abyss-nav-menu-rootThe root element of the NavMenu
.abyss-nav-menu-containerThe viewport container element of the NavMenu
.abyss-nav-menu-drawerThe mobile drawer element
.abyss-nav-menu-drawer-content-wrapperThe wrapper for drawer content

NavMenu.List Classes

Class NameDescription
.abyss-nav-menu-listThe root class for the NavMenu.List component

NavMenu.Item Classes

Class NameDescription
.abyss-nav-menu-menuRoot element
.abyss-nav-menu-menu-activeActive state element

NavMenu.Link Classes

Class NameDescription
.abyss-nav-menu-link-rootRoot element of the menu link
.abyss-nav-menu-linkLink element of the menu item

NavMenu.Trigger Classes

Class NameDescription
.abyss-nav-menu-menu-triggerRoot element of the menu trigger
.abyss-nav-menu-menu-trigger-icon-containerIcon container element of the menu trigger
.abyss-nav-menu-menu-trigger-iconIcon element of the menu trigger

NavMenu.Column Classes

Class NameDescription
.abyss-nav-menu-column-rootRoot element
.abyss-nav-menu-columnColumn element
.abyss-nav-menu-column-titleColumn title element
.abyss-nav-menu-item-link-iconLink icon element
.abyss-nav-menu-column-listColumn list element

NavMenu.Columns Classes

Class NameDescription
.abyss-nav-menu-columns-rootRoot element for the columns container.
.abyss-nav-menu-columns-accordionAccordion wrapper for mobile column accordions.
.abyss-nav-menu-columns-accordion-itemAccordion item for mobile column accordions.
.abyss-nav-menu-columns-accordion-containerContainer for mobile column accordions.
.abyss-nav-menu-columns-content-wrapperWrapper for column content.
.abyss-nav-menu-columns-accordion-triggerTrigger button for mobile column accordions.
.abyss-nav-menu-columns-accordion-titleTitle wrapper for mobile column accordion triggers.
.abyss-nav-menu-columns-accordion-caret-wrapperCaret wrapper for mobile column accordion triggers.
.abyss-nav-menu-columns-accordion-caretCaret icon for mobile column accordion triggers.
.abyss-nav-menu-columns-accordion-contentContent wrapper for mobile column accordions.
.abyss-nav-menu-columns-clickable-titleClickable title for columns with href/onClick.
.abyss-nav-menu-columns-clickable-containerContainer for clickable columns.

NavMenu.MenuItem Classes

Class NameDescription
.abyss-nav-menu-item-rootRoot element
.abyss-nav-menu-item-titleTitle element
.abyss-nav-menu-item-link-iconLink icon element
.abyss-nav-menu-item-descriptionDescription element

NavMenu.Content Classes

Class NameDescription
.abyss-nav-menu-menu-itemRoot element

NavMenu.Divider Classes

Class NameDescription
.abyss-navigation-menu-dropdown-dividerThe horizontal divider between items inside the NavMenu's dropdown

Reduced Motion

Animations and transitions that have been changed when a user has prefers-reduced-motion set to reduced:

  • Transition upon expand/collapse is removed

Implementation

The example below showcases a complex menu that includes all the right accessibility settings

Keyboard Interactions

KeyDescription
TabMoves focus to the next focusable element.
EnterRedirects to the link if the menu bar item is a redirect, or opens the relevant dropdown menu if the item has one.
SpaceIf focus on a menu bar item with a dropdown, opens the relevant dropdown menu.
Left ArrowFocuses the previous menu bar item.
Up ArrowFocuses the previous menu bar item.
Right ArrowFocuses the next menu bar item.
Down ArrowFocuses the next menu bar item. If focus is on an open menu bar item, moves focus into its dropdown menu instead.
EscapeCloses open dropdown menu and moves focus to its menu bar item.
HomeMoves focus to the first item in the menu.
EndMoves focus to the last item in the menu.

Component Tokens

Note: Click on the token row to copy the token to your clipboard.

NavMenu Tokens

Token NameValue
nav-menu.color.surface.container.header
#002677
nav-menu.color.surface.container.viewport
#FFFFFF
nav-menu.color.surface.divider
#CBCCCD
nav-menu.color.surface.interactive.header.rest.default
#002677
nav-menu.color.surface.interactive.header.rest.selected
#196ECF
nav-menu.color.surface.interactive.header.hover.default
#004BA0
nav-menu.color.surface.interactive.header.hover.selected
#004BA0
nav-menu.color.surface.interactive.header.active.default
#00184D
nav-menu.color.surface.interactive.header.active.selected
#00184D
nav-menu.color.icon.content
#FFFFFF
nav-menu.color.text.content
#4B4D4F
nav-menu.color.text.heading.column
#002677
nav-menu.color.text.interactive.header.rest.default
#FFFFFF
nav-menu.color.text.interactive.header.rest.selected
#FFFFFF
nav-menu.color.text.interactive.header.hover.default
#FFFFFF
nav-menu.color.text.interactive.header.hover.selected
#FFFFFF
nav-menu.color.text.interactive.header.active.default
#FFFFFF
nav-menu.color.text.interactive.header.active.selected
#FFFFFF
nav-menu.color.text.interactive.link.default
#196ECF
nav-menu.color.text.interactive.link.hover
#004BA0
nav-menu.color.text.interactive.link.active
#002677
nav-menu.color.border.viewport
#CBCCCD
nav-menu.border-radius.all.viewport
8px
nav-menu.border-radius.bottom.viewport
8px
nav-menu.border-width.divider
1px
nav-menu.border-width.menu
1px
nav-menu.sizing.icon.content
16px
nav-menu.spacing.gap.column.default
12px
nav-menu.spacing.gap.container.columns.default
32px
nav-menu.spacing.gap.container.columns.mobile
16px
nav-menu.spacing.gap.menu.trigger
4px
nav-menu.spacing.gap.menu.items
8px
nav-menu.spacing.margin.vertical.divider
8px
nav-menu.spacing.padding.all.container.columns.default
24px
nav-menu.spacing.padding.all.container.columns.mobile
16px
nav-menu.spacing.padding.left.menu-item
8px
nav-menu.spacing.padding.left.drawer-content
32px
nav-menu.spacing.padding.right.menu-item
8px
nav-menu.spacing.padding.horizontal.container.default
24px
nav-menu.spacing.padding.horizontal.container.mobile
24px
nav-menu.spacing.padding.horizontal.menu.link
24px
nav-menu.spacing.padding.horizontal.menu.trigger
24px
nav-menu.spacing.padding.vertical.menu.link
8px
nav-menu.spacing.padding.vertical.menu.trigger
8px
Table of Contents