Navigation Menu

A collection of links and menus for website navigation.

API reference

Import the component and assemble its parts:

Anatomy

Root

Groups all parts of the navigation menu. Renders a <nav> element at the root, or <div> element when nested.

PropTypeDefault
defaultValue

any

null

value

any

null

onValueChange

((value: any, event: Event | undefined, reason: BaseOpenChangeReason | undefined) => void)

undefined

actionsRef

RefObject<{ unmount: () => void; }>

undefined

onOpenChangeComplete

((open: boolean) => void)

undefined

delay

number

50

closeDelay

number

50

orientation

'horizontal' | 'vertical'

'horizontal'

className

| string
| ((state: NavigationMenu.Root.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Root.State) => ReactElement)

undefined

List

Contains a list of navigation menu items. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.List.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.List.State) => ReactElement)

undefined

Item

An individual navigation menu item. Renders a <div> element.

PropTypeDefault
value

any

undefined

className

| string
| ((state: NavigationMenu.Item.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Item.State) => ReactElement)

undefined

Trigger

Opens the navigation menu popup when hovered or clicked, revealing the associated content. Renders a <button> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Trigger.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Trigger.State) => ReactElement)

undefined

Attribute
Description
data-popup-open
data-pressed

Icon

An icon that indicates that the trigger button opens a menu.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Icon.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Icon.State) => ReactElement)

undefined

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.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Content.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Content.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-activation-direction
data-starting-style
data-ending-style

A link in the navigation menu that can be used to navigate to a different page or section. Renders an <a> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Link.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Link.State) => ReactElement)

undefined

Backdrop

A backdrop for the navigation menu popup. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Backdrop.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Backdrop.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-starting-style
data-ending-style

Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>.

PropTypeDefault
container

| HTMLElement
| RefObject<HTMLElement
| null>
| null

undefined

children

ReactNode

undefined

keepMounted

boolean

false

Positioner

Positions the navigation menu against the currently active trigger. Renders a <div> element.

PropTypeDefault
collisionAvoidance

CollisionAvoidance

undefined

align

'center' | 'start' | 'end'

'center'

alignOffset

number | OffsetFunction

0

side

Side

'bottom'

sideOffset

number | OffsetFunction

0

arrowPadding

number

5

anchor

| Element
| RefObject<Element
| null>
| VirtualElement
| (() => Element | VirtualElement | null)
| null

undefined

collisionBoundary

Boundary

'clipping-ancestors'

collisionPadding

Padding

5

sticky

boolean

false

positionMethod

'fixed' | 'absolute'

'absolute'

trackAnchor

boolean

true

className

| string
| ((state: NavigationMenu.Positioner.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Positioner.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-anchor-hidden
data-align
data-instant
data-side

A container for the navigation menu contents. Renders a <nav> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Popup.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Popup.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-align
data-side
data-starting-style
data-ending-style

Viewport

The clipping viewport of the navigation menu's current content. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Viewport.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Viewport.State) => ReactElement)

undefined

Arrow

Displays an element pointing toward the navigation menu's current anchor. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: NavigationMenu.Arrow.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: NavigationMenu.Arrow.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-uncentered
data-align
data-side

Examples

Nested submenus

A NavigationMenu.Root component can be nested within a higher-level NavigationMenu.Content part to create a multi-level navigation menu.

The NavigationMenu.Link part can be customized to render the link from your framework using the render prop to enable client-side routing.

Next.js example

Large menus

When you have large menu content that doesn’t fit in the viewport in some cases, you usually have two choices:

  1. 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.

Compact layout
  1. Make the navigation menu scrollable
Scrollable layout

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.