import { V1SubNavigationMenu } from '@uhg-abyss/web/ui/SubNavigationMenu';Usage
Utilize V1SubNavigationMenu to create a navigation menu on the side of your web page.
Scroll
When the Menu has overflow it will begin to scroll.
Title
Use the title prop to pass in a title for the Menu.
SubText
Use the subText prop to pass in a description for the Menu.
HeadingLevel
Use the headingLevel prop to pass in a specified headingLevel for the title. The default is h3.
When using V1SubNavigationMenu
In <main> content (such as a "left nav"):
- `it is likely appropriate for titleTag to be a page heading
- Set titleTag to "h2" to "h6" to correctly nest in the heading hierarchy (to create
<h2> to <h6>)
As part of a larger navigation element (such as NavMenu):
- it is appropriate for titleTag to be an element that correctly nests in the parent
- Set titleTag to "div" to create
<div>or other appropriate child element
Width
Use the width prop to set the width of the menu. Defaults to 320px.
Height
Use the height prop to set the height of the menu. Defaults to 100%.
NavItems
Use the navItems prop to specify what is displayed in the V1SubNavigationMenu. The prop requires an array of objects that have the form:
navItems: [ { title: 'string', href: 'string', isDisabled: 'boolean', before: 'node', after: 'node', onClick: 'func', openNewWindow: 'boolean', subItems: 'object[]', isOpenByDefault: 'boolean', removeCollapse: 'boolean', },];navItemscan have either anhrefor a subset of NavItems insubItems.navItemsalso takesopenNewWindow, which will open a new window when the link is clicked. If a non-relative path (like https://google.comopens in a new window) is passed, then openNewWindow will betrueby default; otherwise, it will befalseby default.- If
subItemsis specified, then the object will be recognized as a dropdown. You can utilizeisOpenByDefaultto specify if the dropdown starts out open or closed (isOpenByDefaultis set tofalseby default). removeCollapsecan be set to true to display all menu sub-items without the collapse functionality. By Default, it is set tofalseand collapse functionality is enabled.beforeandaftercan be used to place icons or nodes before or after the menu item.
Set active
V1SubNavigationMenu will inherently determine if the current location path matches a nav-item path and apply the default active state styles.
If you'd like to override this default behavior and manually handle setting of the active state, you can use the setActive prop. setActive is a function that's called as part of a loop through all nav-menu items on render and provides a single argument with each nav-menu item. Return true to the item you'd like the default active state styling to be applied. Custom styling can be accomplished by targeting the abyss-sub-navigation-menu-link-active class.
Multi level dropdowns
V1SubNavigationMenu supports up to three levels of dropdown items. To supply an additional level, pass in an array of sub-item objects to the subItems property on the sub-item dropdown you'd like it to be applied.
Controlled expansion state
Use the expandedItems, and onToggleExpansion props to control open/closed state of dropdowns externally.
Both of these props must be provided to enable controlled expansion.
isOpenByDefault is no longer applicable when using controlled expansion.
{ const [expandedItems, setExpandedItems] = React.useState({ '0': false, '0-0': false, }); const toggleExpansion = (path: string, nextOpen: boolean) => { setExpandedItems((prev) => ({ ...prev, [path]: nextOpen, })); }; //...
return ( <V1SubNavigationMenu expandedItems={expandedItems} onToggleExpansion={toggleExpansion} //... /> );}Default selection example
Closing nested dropdowns when closing parent
Programmatic control example
Clickable header title
To render the V1SubNavigationMenu header title as a link, pass in an href to the titleHref prop. To render as a button, pass in a callback function to titleOnClick.
titleHref
titleOnClick
Side bar menu
Pass in the prop variant and set the value to sideBarMenu in order to turn your V1SubNavigationMenu into a side bar menu that lists out all available links.
Position
Set the position prop to left when aligning the sideBarMenu variant to the right side of the screen. This will move the active indicator to the left side and update the menu alignment. position is set to right by default
V1SubNavigationMenu Props
| Name | Type | Default | A11y | Description |
|---|---|---|---|---|
className | string | undefined | CSS class name to apply to each element within the component | ||
css | CSSProperties | Partial<Record<"abyss-sub-navigation-menu-root" | "abyss-sub-navigation-header-container" | "abyss-sub-navigation-header-title" | "abyss-sub-navigation-header-text" | ... 9 more ... | "abyss-sub-navigation-dropdown-list-container", CSSProperties>> | undefined | 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 | undefined | Suffix used to create a unique ID used for automated testing See Component Testing for more information | ||
expandedItems | Record<string, boolean> | undefined | Controlled expansion state for all dropdowns. | ||
headingLevel | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | undefined | 'h3' | The semantic heading level for the menu's title, so it fits correctly into the page's heading structure for screen readers. | |
height | string | number | undefined | '100%' | The height of the SubNavigationMenu component. | |
hiddenFrom | Breakpoint | undefined | When defined, the component is hidden once the screen width reaches the specified breakpoint. | ||
navItems | SubNavigationMenuNavItem[] | undefined | The navigation items for the SubNavigationMenu component. | ||
onToggleExpansion | ((path: string, nextOpen: boolean) => void) | undefined | Callback fired when a dropdown's expansion state changes. | ||
position | "left" | "right" | undefined | 'right' | The position of the SubNavigationMenu component. | |
setActive | ((menuItem: SubNavigationMenuNavItem) => boolean) | undefined | The callback function to set the active state of a menu item. | ||
slotProps | Partial<Record<string, SlotPropsValue<string>>> | undefined | Props to pass to individual internal slots of the component, keyed by the slot name (e.g. 'button-root'). Supports className, css, style, aria-*, data-*, data-testid, and nested slotProps for child Abyss components. See slotProps for more information | ||
subText | string | undefined | The subtext for the SubNavigationMenu component. | ||
title | string | undefined | The title for the SubNavigationMenu component. | ||
titleHref | string | undefined | The href for the title of the SubNavigationMenu component. Renders title as a link. | ||
titleOnClick | MouseEventHandler<HTMLElement> | The onClick event handler for the title of the SubNavigationMenu component. Renders title as a button. | ||
titleRouterComponent | ComponentType<any> | undefined | Custom router component to use for client-side navigation on title link (e.g., Next.js Link, Gatsby Link, etc.) | ||
variant | "default" | "sideBarMenu" | undefined | 'default' | The variant of the SubNavigationMenu component. - 'default': Default variant. - 'sideBarMenu': Converts SubNavigationMenu into a side bar menu | |
visibleFrom | Breakpoint | undefined | When defined, the component is hidden until the screen width reaches the specified breakpoint. | ||
width | string | number | undefined | '320px' | The width of the SubNavigationMenu component. |
V1SubNavigationMenu Classes
| Class Name | Description |
|---|---|
| .abyss-sub-navigation-dropdown-button | Dropdown button |
| .abyss-sub-navigation-dropdown-button-chevron | Button Chevron |
| .abyss-sub-navigation-dropdown-container | Dropdown container |
| .abyss-sub-navigation-dropdown-list-container | Dropdown links container |
| .abyss-sub-navigation-dropdown-title | Dropdown title/link |
| .abyss-sub-navigation-dropdown-wrapper | Dropdown wrapping title and button |
| .abyss-sub-navigation-header-container | Header container |
| .abyss-sub-navigation-header-text | Header subText |
| .abyss-sub-navigation-header-title | Header title |
| .abyss-sub-navigation-menu-item | Menu List item |
| .abyss-sub-navigation-menu-items | Menu items unordered list |
| .abyss-sub-navigation-menu-link | Menu Link |
| .abyss-sub-navigation-menu-link-active | Menu Link Active |
| .abyss-sub-navigation-menu-root | SubNavigationMenu root element |
For icon accessibility, please refer to the IconSymbol docs.
V1SubNavigationMenu is a WAI-ARIA Tree View patternopens in a new window that follows the Navigation Treeview Exampleopens in a new window and "Disclosure" approach described in the notes. This is so default operation is more predictable using tabs for website navigation. Arrow key implementation is more appropriate for a web application.
Keyboard Interactions
| Key | Description |
|---|---|
| Tab | Traverse the SubNavMenu |
| Enter | Select a SubNavMenu item. When hitting Enter on a dropdown, it will open/close the dropdown |
| Down Arrow | Moves focus to the next node that is focusable without opening or closing a node |
| Up Arrow | Moves focus to the previous node that is focusable without opening or closing a node |
| Home | Moves focus to the first node in the tree without opening or closing a node |
| End | Moves focus to the last node in the tree that is focusable without opening a node |
| Right Arrow | Focus is on a closed dropdown, opens the dropdown; focus does not move |
| Left Arrow | Focus is on an open dropdown, closes the dropdown |
| A-Z or a-z | Moves focus to the next menu item with a label that starts with the typed character if such an menu item exists. Otherwise, focus does not move |