Examples
Grouped
The following example shows two navigation groups, each with a title
prop passed into the nav group component. To keep nav groups accessible an aria-label
must be passed in if the title
prop is not passed in.
Flyout
A flyout should be a Menu
component. Press space
or right arrow
to open a flyout using the keyboard, use the arrow keys to navigate between flyout items, and press escape
or left arrow
to close a flyout.
Types
NavSelectClickHandler
The NavItem onClick
prop accepts the NavSelectClickHandler
type, which is made up of the following argument and return types:
(
event: React.FormEvent<HTMLInputElement>,
itemId: number | string,
groupId: number | string,
to: string
) => void;
Props
Nav
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | Accessible label for the nav when there are multiple navs on the page | |
children | React.ReactNode | Anything that can be rendered inside of the nav | |
className | string | Additional classes added to the container | |
onSelect | ( event: React.FormEvent<HTMLInputElement>, selectedItem: { groupId: number | string; itemId: number | string; to: string; } ) => void | () => undefined | Callback for updating when item selection changes |
onToggle | ( event: React.MouseEvent<HTMLButtonElement>, toggledItem: { groupId: number | string; isExpanded: boolean; } ) => void | () => undefined | Callback for when a list is expanded or collapsed |
ouiaId | number | string | Value to overwrite the randomly generated data-ouia-component-id. | |
ouiaSafe | boolean | true | Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. |
variant | 'default' | 'horizontal' | 'horizontal-subnav' | For horizontal navs |
NavList
Name | Type | Default | Description |
---|---|---|---|
backScrollAriaLabel | string | 'Scroll back' | Aria-label for the back scroll button |
children | React.ReactNode | Children nodes | |
className | string | Additional classes added to the list | |
forwardScrollAriaLabel | string | 'Scroll foward' | Aria-label for the forward scroll button |
NavGroup
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | null | Anything that can be rendered inside of the group |
className | string | '' | Additional classes added to the container |
id | string | getUniqueId() | Identifier to use for the section aria label |
title | string | Title shown for the group |
NavItem
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | Content rendered inside the nav item. | |
className | string | Additional classes added to the nav item | |
component | React.ElementType<any> | React.ComponentType<any> | 'a' | Component used to render NavItems if React.isValidElement(children) is false |
flyout | React.ReactElement | Flyout of a nav item. This should be a Menu component. Should not be used if the to prop is defined. | |
groupId | string | number | null | null | Group identifier, will be returned with the onToggle and onSelect callback passed to the Nav component |
icon | React.ReactNode | Icon added before the nav item children. | |
isActive | boolean | false | Flag indicating whether the item is active |
itemId | string | number | null | null | Item identifier, will be returned with the onToggle and onSelect callback passed to the Nav component |
onClick | NavSelectClickHandler | Callback for item click | |
onShowFlyout | () => void | Callback when flyout is opened or closed | |
ouiaId | number | string | Value to overwrite the randomly generated data-ouia-component-id. | |
ouiaSafe | boolean | Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. | |
preventDefault | boolean | false | If true prevents the default anchor link action to occur. Set to true if you want to handle navigation yourself. |
styleChildren | boolean | true | Whether to set className on children when React.isValidElement(children) |
to | string | Target navigation link. Should not be used if the flyout prop is defined. | |
zIndex | number | 9999 | z-index of the flyout nav item |
NavItemSeparator
Name | Type | Default | Description |
---|---|---|---|
component | No type info | 'li' |
NavExpandable
Name | Type | Default | Description |
---|---|---|---|
titlerequired | React.ReactNode | Title content shown for the expandable list | |
buttonProps | any | Additional props added to the NavExpandable <button> | |
children | React.ReactNode | '' | Anything that can be rendered inside of the expandable list |
className | string | '' | Additional classes added to the container |
groupId | string | number | null | Group identifier, will be returned with the onToggle and onSelect callback passed to the Nav component |
id | string | '' | Identifier to use for the section aria label |
isActive | boolean | false | If true makes the expandable list title active |
isExpanded | boolean | false | Boolean to programatically expand or collapse section |
onExpand | (event: React.MouseEvent<HTMLButtonElement, MouseEvent>, val: boolean) => void | allow consumer to optionally override this callback and manage expand state externally. if passed will not call Nav's onToggle. | |
ouiaId | number | string | Value to overwrite the randomly generated data-ouia-component-id. | |
srText | string | '' | If defined, screen readers will read this text instead of the list title |
CSS variables
Expand or collapse column | Selector | Variable | Value | |
---|---|---|---|---|
.pf-v6-c-nav | --pf-v6-c-nav__link--PaddingBlockStart | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--PaddingBlockEnd | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__list--RowGap | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__list--ColumnGap | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--PaddingBlockStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--PaddingBlockEnd | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--PaddingInlineStart | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--PaddingInlineEnd | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--RowGap | 1.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--ColumnGap | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--AlignItems | baseline | ||
.pf-v6-c-nav | --pf-v6-c-nav--FontSize | 0.875rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--FontWeight | 400 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--LineHeight | 1.5 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--OutlineOffset | calc(0.25rem * -1) | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--BackgroundColor | transparent | ||
.pf-v6-c-nav | --pf-v6-c-nav__list--ScrollSnapTypeAxis | x | ||
.pf-v6-c-nav | --pf-v6-c-nav__list--ScrollSnapTypeStrictness | proximity | ||
.pf-v6-c-nav | --pf-v6-c-nav__list--ScrollSnapType | x proximity | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__item--ScrollSnapAlign | end | ||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--FontWeight | 500 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--Color | (In light theme) #151515 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--PaddingBlockStart | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--PaddingBlockEnd | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__section-title--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__item--RowGap | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__item__toggle-icon--Rotate | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav__item--m-expanded__toggle-icon--Rotate | 90deg | ||
.pf-v6-c-nav | --pf-v6-c-nav__link--ColumnGap | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--AlignItems | baseline | ||
.pf-v6-c-nav | --pf-v6-c-nav__link--BorderRadius | 6px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--BackgroundColor | (In light theme) rgba(255, 255, 255, 0.0000) | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--WhiteSpace | normal | ||
.pf-v6-c-nav | --pf-v6-c-nav__link--Color | (In light theme) #4d4d4d | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--hover--Color | (In light theme) #151515 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--hover--BackgroundColor | (In light theme) #ffffff | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--m-current--BackgroundColor | (In light theme) #ffffff | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--m-current--Color | (In light theme) #151515 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link-icon--Color | (In light theme) #707070 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__link--m-current__link-icon--Color | (In light theme) #1f1f1f | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__subnav--RowGap | 3px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__subnav--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--BorderColor | (In light theme) #c7c7c7 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--BorderWidth | 1px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--first-of-type--c-button--BorderStartStartRadius | 999px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--first-of-type--c-button--BorderEndStartRadius | 999px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--last-of-type--c-button--BorderStartEndRadius | 999px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__scroll-button--last-of-type--c-button--BorderEndEndRadius | 999px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__toggle--PaddingInlineStart | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__toggle--PaddingInlineEnd | 0.5rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav__toggle--TranslateY | calc((1.5 * 0.875rem / 2) - 50%) | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal__list--PaddingBlockStart | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal__list--PaddingBlockEnd | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal__list--PaddingInlineStart | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal__list--PaddingInlineEnd | 0 | ||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-scrollable__list--PaddingInlineStart | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-scrollable__list--PaddingInlineEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav--BackgroundColor | (In light theme) #f2f2f2 | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav--BorderRadius | 999px | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__list--PaddingBlockStart | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__list--PaddingBlockEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__list--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__list--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav--m-scrollable__list--PaddingInlineStart | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav--m-scrollable__list--PaddingInlineEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__link--PaddingBlockStart | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__link--PaddingBlockEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__link--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav | --pf-v6-c-nav--m-horizontal--m-subnav__link--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav.pf-m-inset | --pf-v6-c-nav--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav.pf-m-inset | --pf-v6-c-nav--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav .pf-v6-c-menu | --pf-v6-c-menu--MinWidth | 100% | ||
.pf-v6-c-nav .pf-v6-c-menu.pf-m-drilldown | --pf-v6-c-menu--PaddingBlockStart | 0 | ||
.pf-v6-c-nav .pf-v6-c-menu.pf-m-drilldown | --pf-v6-c-menu--PaddingBlockEnd | 0 | ||
.pf-v6-c-nav .pf-v6-c-menu.pf-m-drilldown | --pf-v6-c-menu--BackgroundColor | transparent | ||
| ||||
.pf-v6-c-nav .pf-v6-c-menu.pf-m-drilldown | --pf-v6-c-menu--BoxShadow | none | ||
.pf-v6-c-nav .pf-v6-c-menu.pf-m-drilldown | --pf-v6-c-menu__list-item--hover--BackgroundColor | (In light theme) #ffffff | ||
| ||||
.pf-v6-c-nav__nav | --pf-v6-c-nav__item--RowGap--row-offset | calc(0.5rem / 2 * -1) | ||
| ||||
.pf-v6-c-nav__nav | --pf-v6-c-nav__link--clickable-inset--Block | calc(0.5rem / 2 * -1) | ||
| ||||
.pf-v6-c-nav__nav | --pf-v6-c-nav__button--RowGap--row-offset | calc(0.5rem * -1) | ||
| ||||
.pf-v6-c-nav__subnav | --pf-v6-c-nav__list--RowGap | 3px | ||
| ||||
.pf-v6-c-nav__link.pf-m-current | --pf-v6-c-nav__link-icon--Color | (In light theme) #1f1f1f | ||
| ||||
.pf-v6-c-nav__item:where(.pf-m-flyout) .pf-v6-c-nav__toggle-icon | --pf-v6-c-nav__item--m-expanded__toggle-icon--Rotate | 0 | ||
.pf-v6-c-nav__scroll-button:first-of-type .pf-v6-c-button | --pf-v6-c-button--BorderStartStartRadius | 999px | ||
| ||||
.pf-v6-c-nav__scroll-button:first-of-type .pf-v6-c-button | --pf-v6-c-button--BorderEndStartRadius | 999px | ||
| ||||
.pf-v6-c-nav__scroll-button:last-of-type .pf-v6-c-button | --pf-v6-c-button--BorderStartEndRadius | 999px | ||
| ||||
.pf-v6-c-nav__scroll-button:last-of-type .pf-v6-c-button | --pf-v6-c-button--BorderEndEndRadius | 999px | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--BackgroundColor | (In light theme) #f2f2f2 | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal__list--PaddingBlockStart | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal__list--PaddingBlockEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal__list--PaddingInlineStart | 1rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal__list--PaddingInlineEnd | 1rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal--m-scrollable__list--PaddingInlineStart | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav--m-horizontal--m-scrollable__list--PaddingInlineEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav__link--PaddingBlockStart | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-subnav | --pf-v6-c-nav__link--PaddingBlockEnd | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-scrollable | --pf-v6-c-nav--m-horizontal__list--PaddingInlineStart | 0.25rem | ||
| ||||
.pf-v6-c-nav:where(.pf-m-horizontal).pf-m-scrollable | --pf-v6-c-nav--m-horizontal__list--PaddingInlineEnd | 0.25rem | ||
|