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.com) 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.
Note:: 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
| Prop Name | Type | Default | Description |
|---|---|---|---|
| headingLevel | h1 | h2 | h3 | h4 | h5 | h6 | h3 | changes the heading level of the title. defaults to h3 |
| height | string | number | 100% | changes the height of the menu. Defaults to 100% |
| navItems | object[] | [] | Array of menu items. { title: string, isDisabled: boolean, href: string, before: node, after: node, isOpenByDefault: boolean, subItems: object[], openNewWindow: boolean, onClick: function, isActive: boolean, removeCollapse: boolean} |
| onClick | function | - | Callback fired when the dropdown is clicked |
| position | left | right | right | Positions nav on the left or right side |
| setActive | function | - | Callback function to manually set active state for nav-menu links |
| subText | string | - | Description of the V1SubNavigationMenu |
| title | string | - | Title of the SubNavigrationMenu |
| titleHref | string | - | Adds a link to V1SubNavigationMenu header title |
| titleOnClick | function | - | Callback function fired when V1SubNavigationMenu header title is clicked |
| variant | default | sideBarMenu | default | changes V1SubNavigationMenu into a sideBarMenu |
| width | string | number | 320px | changes the width of the menu |
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 | root element |
For icon accessibility, please refer to the IconSymbol docs.
V1SubNavigationMenu is a WAI-ARIA Tree View pattern that follows the Navigation Treeview Example 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 |