Navigation Menu
A collection of links and menus for website navigation.
API reference
Import the component and assemble its parts:
import { NavigationMenu } from '@base-ui-components/react/navigation-menu';
<NavigationMenu.Root>
<NavigationMenu.List>
<NavigationMenu.Item>
<NavigationMenu.Trigger>
<NavigationMenu.Icon />
</NavigationMenu.Trigger>
<NavigationMenu.Content>
<NavigationMenu.Link />
</NavigationMenu.Content>
</NavigationMenu.Item>
</NavigationMenu.List>
<NavigationMenu.Portal>
<NavigationMenu.Backdrop />
<NavigationMenu.Positioner>
<NavigationMenu.Popup>
<NavigationMenu.Arrow />
<NavigationMenu.Viewport />
</NavigationMenu.Popup>
</NavigationMenu.Positioner>
</NavigationMenu.Portal>
</NavigationMenu.Root>
Root
Groups all parts of the navigation menu.
Renders a <nav>
element at the root, or <div>
element when nested.
Prop | Type | Default | |
---|---|---|---|
defaultValue |
|
| |
value |
|
| |
onValueChange |
|
| |
actionsRef |
|
| |
onOpenChangeComplete |
|
| |
delay |
|
| |
closeDelay |
|
| |
orientation |
|
| |
className |
|
| |
render |
|
|
List
Contains a list of navigation menu items.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Item
An individual navigation menu item.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
value |
|
| |
className |
|
| |
render |
|
|
Trigger
Opens the navigation menu popup when hovered or clicked, revealing the
associated content.
Renders a <button>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-popup-open | Present when the corresponding navigation menu is open. | |
data-pressed | Present when the trigger is pressed. |
Icon
An icon that indicates that the trigger button opens a menu.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Content
A container for the content of the navigation menu item that is moved into the popup
when the item is active.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-activation-direction | Which direction another trigger was activated from. | |
data-starting-style | Present when the content is animating in. | |
data-ending-style | Present when the content is animating out. |
Link
A link in the navigation menu that can be used to navigate to a different page or section.
Renders an <a>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Backdrop
A backdrop for the navigation menu popup.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-starting-style | Present when the popup is animating in. | |
data-ending-style | Present when the popup is animating out. |
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>
.
Prop | Type | Default | |
---|---|---|---|
container |
|
| |
children |
|
| |
keepMounted |
|
|
Positioner
Positions the navigation menu against the currently active trigger.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
collisionAvoidance |
|
| |
align |
|
| |
alignOffset |
|
| |
side |
|
| |
sideOffset |
|
| |
arrowPadding |
|
| |
anchor |
|
| |
collisionBoundary |
|
| |
collisionPadding |
|
| |
sticky |
|
| |
positionMethod |
|
| |
trackAnchor |
|
| |
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-anchor-hidden | Present when the anchor is hidden. | |
data-align | Indicates how the popup is aligned relative to the specified side. | |
data-instant | Present if animations should be instant. | |
data-side | Indicates which side the popup is positioned relative to the trigger. |
Popup
A container for the navigation menu contents.
Renders a <nav>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-align | Indicates how the popup is aligned relative to the specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-starting-style | Present when the popup is animating in. | |
data-ending-style | Present when the popup is animating out. |
Viewport
The clipping viewport of the navigation menu's current content.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Arrow
Displays an element pointing toward the navigation menu's current anchor.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className |
|
| |
render |
|
|
Attribute | Description | |
---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-uncentered | Present when the popup arrow is uncentered. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. |
Examples
Nested submenus
A NavigationMenu.Root
component can be nested within a higher-level NavigationMenu.Content
part to create a multi-level navigation menu.
Custom links
The NavigationMenu.Link
part can be customized to render the link from your framework using the render
prop to enable client-side routing.
import NextLink from 'next/link';
import { NavigationMenu } from '@base-ui-components/react/navigation-menu';
function Link(props: NavigationMenu.Link.Props) {
return (
<NavigationMenu.Link
render={<NextLink href={props.href} />}
{...props}
/>
);
}
Large menus
When you have large menu content that doesn’t fit in the viewport in some cases, you usually have two choices:
- Compress the navigation menu content
You can change the layout of the navigation menu to render less content or be more compact by reducing the space it takes up. If your content is flexible, you can use the max-height
property on Popup
to limit the height of the navigation menu to let it compress itself while preventing overflow.
.Popup {
max-height: var(--available-height);
}
- Make the navigation menu scrollable
.Popup {
max-height var(--available-height);
}
.Content {
overflow-y: auto;
}
Native scrollbars will be visible while transitioning content, so we recommend using our Scroll Area component instead of native scrollbars to keep them hidden, which will also allow the Arrow
to be centered correctly.