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.
NavMenu.Root
The NavMenu.Root is the provider component that contains all NavMenu subcomponents and accepts the following props:
-
hasOverlayis used to show or hide the overlay when a dropdown menu is opened. The default value isfalse. -
zIndexprovides the ability to set the z-index value of the navigation menu. IfhasOverlayis 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 is101. -
enableOutsideScrollis used to allow the user to scroll, even when a navigation dropdown item is open. The default value isfalse. -
stickyprovides the ability to position the navigation menu at the top of the viewport. -
mobileDraweris used to render the navigation menu in a drawer instead of a dropdown on mobile screen sizes. The default value istrue.
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.
NavMenu.List
The NavMenu.List component is a wrapper for the top level menu items and should contain NavMenu.Link or NavMenu.Item as direct children.
NavMenu.Link
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.
Dropdown menu
Use the following components to add a dropdown menu to the top level navigation menu.
NavMenu.Item
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.
NavMenu.Divider
The NavMenu.Divider is a simple divider line component that allows you to add a visual separator between different NavMenu.Item components.
NavMenu.Trigger
The NavMenu.Trigger component is a button element that toggles viewing of the dropdown menu content.
Dropdown menu content
Use the following components to construct the content for the dropdown menu.
NavMenu.Content
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.
NavMenu.Columns
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.
NavMenu.Column
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.
NavMenu.MenuItem
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.
NavMenu.MenuItemUnstyled
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
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 |
data-testid | string | - | - | Suffix used to create a unique ID used for automated testing |
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 Name | Description |
|---|---|
| .abyss-nav-menu-portal | The portal element of the NavMenu |
| .abyss-nav-menu-overlay | The overlay element of the NavMenu |
| .abyss-nav-menu-root | The root element of the NavMenu |
| .abyss-nav-menu-container | The viewport container element of the NavMenu |
| .abyss-nav-menu-drawer | The mobile drawer element |
| .abyss-nav-menu-drawer-content-wrapper | The wrapper for drawer content |
NavMenu.List Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-list | The root class for the NavMenu.List component |
NavMenu.Item Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-menu | Root element |
| .abyss-nav-menu-menu-active | Active state element |
NavMenu.Link Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-link-root | Root element of the menu link |
| .abyss-nav-menu-link | Link element of the menu item |
NavMenu.Trigger Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-menu-trigger | Root element of the menu trigger |
| .abyss-nav-menu-menu-trigger-icon-container | Icon container element of the menu trigger |
| .abyss-nav-menu-menu-trigger-icon | Icon element of the menu trigger |
NavMenu.Column Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-column-root | Root element |
| .abyss-nav-menu-column | Column element |
| .abyss-nav-menu-column-title | Column title element |
| .abyss-nav-menu-item-link-icon | Link icon element |
| .abyss-nav-menu-column-list | Column list element |
NavMenu.Columns Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-columns-root | Root element for the columns container. |
| .abyss-nav-menu-columns-accordion | Accordion wrapper for mobile column accordions. |
| .abyss-nav-menu-columns-accordion-item | Accordion item for mobile column accordions. |
| .abyss-nav-menu-columns-accordion-container | Container for mobile column accordions. |
| .abyss-nav-menu-columns-content-wrapper | Wrapper for column content. |
| .abyss-nav-menu-columns-accordion-trigger | Trigger button for mobile column accordions. |
| .abyss-nav-menu-columns-accordion-title | Title wrapper for mobile column accordion triggers. |
| .abyss-nav-menu-columns-accordion-caret-wrapper | Caret wrapper for mobile column accordion triggers. |
| .abyss-nav-menu-columns-accordion-caret | Caret icon for mobile column accordion triggers. |
| .abyss-nav-menu-columns-accordion-content | Content wrapper for mobile column accordions. |
| .abyss-nav-menu-columns-clickable-title | Clickable title for columns with href/onClick. |
| .abyss-nav-menu-columns-clickable-container | Container for clickable columns. |
NavMenu.MenuItem Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-item-root | Root element |
| .abyss-nav-menu-item-title | Title element |
| .abyss-nav-menu-item-link-icon | Link icon element |
| .abyss-nav-menu-item-description | Description element |
NavMenu.Content Classes
| Class Name | Description |
|---|---|
| .abyss-nav-menu-menu-item | Root element |
NavMenu.Divider Classes
| Class Name | Description |
|---|---|
| .abyss-navigation-menu-dropdown-divider | The 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
| Key | Description |
|---|---|
| Tab | Moves focus to the next focusable element. |
| Enter | Redirects to the link if the menu bar item is a redirect, or opens the relevant dropdown menu if the item has one. |
| Space | If focus on a menu bar item with a dropdown, opens the relevant dropdown menu. |
| Left Arrow | Focuses the previous menu bar item. |
| Up Arrow | Focuses the previous menu bar item. |
| Right Arrow | Focuses the next menu bar item. |
| Down Arrow | Focuses the next menu bar item. If focus is on an open menu bar item, moves focus into its dropdown menu instead. |
| Escape | Closes open dropdown menu and moves focus to its menu bar item. |
| Home | Moves focus to the first item in the menu. |
| End | Moves 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 Name | Value | |
|---|---|---|
| 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 |