Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Navigation Menu for Ark UI

A header navigation bar for React on Ark UI: top-level links in a row, some opening a panel of related pages, for docs and marketing sites.

On this page9 sections

A navigation menu is the row of links across a site's header. Some items go straight to a page, and others open a panel of related pages under their trigger: product areas, a grid of docs sections, a list of resources. It renders a nav element, so screen reader users can jump straight to it.

For the many destinations of an app, use a Sidebar. Actions such as Export or Delete belong in a Dropdown Menu.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Navigation Menu anatomy: list, trigger, indicator, content, link

Usage

import {
  NavigationMenu, NavigationMenuContent, NavigationMenuItem,
  NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger,
  navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu";

Each NavigationMenuItem holds either a trigger with its content or a single link. Give a top-level link the classes from navigationMenuTriggerStyle() so it lines up with the triggers beside it.

<NavigationMenu>
  <NavigationMenuList>
    <NavigationMenuItem>
      <NavigationMenuTrigger>Products</NavigationMenuTrigger>
      <NavigationMenuContent>
        <ul className="grid w-64 gap-1">
          <li>
            <NavigationMenuLink href="/analytics">Analytics</NavigationMenuLink>
          </li>
          <li>
            <NavigationMenuLink href="/billing">Billing</NavigationMenuLink>
          </li>
        </ul>
      </NavigationMenuContent>
    </NavigationMenuItem>
    <NavigationMenuItem>
      <NavigationMenuLink className={navigationMenuTriggerStyle()} href="/pricing">
        Pricing
      </NavigationMenuLink>
    </NavigationMenuItem>
  </NavigationMenuList>
</NavigationMenu>

Accessibility

NavigationMenu renders a nav element, and each item with a panel is a popover of its own. Its trigger is a button that reports aria-expanded, and the panel is a non-modal dialog named after that trigger, or after an aria-label you give NavigationMenuContent. Opening a panel moves focus to its first link, tabbing past the last link moves on along the bar and closes it, and Escape or choosing a link closes it and returns focus to the trigger. Give the nav an aria-label when the page has a second navigation landmark.

Enter
On a trigger, opens or closes its panel, and opening moves focus to the panel's first link. On a link, follows it and closes the panel.
Space
On a trigger, opens or closes its panel, and opening moves focus to the panel's first link.
Tab
Moves focus to the next trigger or link. From the last link of an open panel, moves on to the item after its trigger and closes the panel.
Shift+Tab
Moves focus back, and from the first link of an open panel to its trigger.
Escape
Closes the open panel and returns focus to its trigger.

Demos

RTL

The default header in Arabic, inside a Direction provider set to right to left and a wrapper with dir set to rtl. The wrapper turns the bar, and the provider turns the panels, which open in a portal outside the wrapper and don't take its direction. Start from it for an Arabic or Hebrew header.

Preview width

FAQ

Why does the Navigation Menu panel stay open after I click a link?

It shouldn't: a NavigationMenuLink closes the panel it sits in when it's clicked, unless ⌘ or Ctrl is held to open it in a new tab. A panel that stays open usually holds a plain anchor or a router link that isn't rendered through NavigationMenuLink, so render it through asChild. Set closeOnClick to false on a link that should leave the panel open.

Does the Ark UI Navigation Menu open on hover, and can I change the delay?

No. Each panel is a popover that opens on a click or with Enter or Space, so nothing pops open as the pointer crosses the header and there is no delay to tune. If you drive an item's open from pointer events to add hover, keep the click working, since touch screens and keyboards have no hover.

How do I control which Navigation Menu panel is open in React?

There is no menu-wide value, because each NavigationMenuItem is a popover of its own. Pass open and onOpenChange to the item you want to control, and read details.open in the callback. Nothing keeps two panels from being open at once if your state says so, so close the others when one opens.

How do I highlight the current page in the Navigation Menu?

Set aria-current to page on the NavigationMenuLink whose address matches the current route. Screen readers announce it as the current page, and Tailwind's aria-[current=page]: variant styles it with no second prop. When the page sits inside a panel, mark that panel's trigger with a class of your own so the bar shows the section.

How do I set the width of a Navigation Menu panel?

A panel is as wide as what you put in it, so set the width on the list inside NavigationMenuContent. The demos use w-96 for the Getting started list and a grid that grows from 400 to 600 pixels with the screen.

Each panel opens under its own trigger, lined up with the trigger's start edge, and is capped at the screen width less 2rem. Pass positioning to NavigationMenuItem to move it, with a placement of bottom to center it under the trigger.

How do I make the Navigation Menu work on mobile?

The bar has no small-screen layout of its own: its items stay in one row, and a wide panel is squeezed to fit the screen. Below a breakpoint, hide the menu with a class such as hidden md:flex and put the same links in a Sheet behind a menu button, where each one gets a full-width tap target.

The demos already hide the Components item below md for this reason.

When should I use a Navigation Menu instead of a Dropdown Menu or a Menubar?

Use a Navigation Menu to move between the pages of a site, where every item is a link or opens a panel of links. A Dropdown Menu holds actions on the current page, such as Export or Delete, with menu roles and keys built for commands.

A Menubar is an app's row of File, Edit and View menus. When an app has dozens of destinations, a Sidebar keeps them in view instead.

API Reference

<nav> data-slot="navigation-menu"

PropType
className?string

Merged with the part's classes.

<li>

PropType
open?boolean

The controlled open state of the popover.

defaultOpen?boolean

The initial open state of the popover when rendered. Use when you don't need to control the open state of the popover.

onOpenChange?(details: OpenChangeDetails) → void

Function invoked when the popover opens or closes.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
triggerValue?string | null

The controlled trigger value.

Type
string | null
defaultTriggerValue?string | null

The initial trigger value when rendered. Use when you don't need to control the trigger value.

Type
string | null
onTriggerValueChange?(details: TriggerValueChangeDetails) → void

Function called when the trigger value changes.

Type
(details: TriggerValueChangeDetails) → void
Parameters

details – { value: string | null; triggerElement: HTMLElement | null }

Returns
void
autoFocus?boolean

Whether to automatically set focus on the first focusable content within the popover when opened.

Default
true
closeOnEscape?boolean

Whether to close the popover when the escape key is pressed.

Default
true
closeOnInteractOutside?boolean

Whether to close the popover when the user clicks outside of the popover.

Default
true
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
finalFocusEl?() → MaybeElement

Element to receive focus when the popover is closed.

Returns
MaybeElement
hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the popover. Useful for composition.

Type
{ anchor?: string; trigger?: string | ((value?: string) → string); content?: string; title?: string; description?: string; closeTrigger?: string; positioner?: string; arrow?: string }
immediate?boolean

Whether to synchronize the present change immediately or defer it to the next frame.

initialFocusEl?() → HTMLElement | null | false

The element to focus on when the popover is opened. Return false to skip moving focus, or null to use the default.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
lazyMount?boolean

Whether to enable lazy mounting. Ark default: false.

Default
true
modal?boolean

Whether the popover should be modal. When set to true: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover

Default
false
onEnterComplete?VoidFunction

Function called when the animation ends in the open state.

onEscapeKeyDown?(event: KeyboardEvent) → void

Function called when the escape key is pressed.

Parameters

event – { altKey: boolean; charCode: number; ctrlKey: boolean; code: string; getModifierState: (key: string) → boolean; key: string; keyCode: number; locale: string; location: number; metaKey: boolean; repeat: boolean; shiftKey: boolean; which: number }

Returns
void
onExitComplete?VoidFunction

Function called when the animation ends in the closed state.

onFocusOutside?(event: FocusOutsideEvent) → void

Function called when the focus is moved outside the component.

Type
(event: FocusOutsideEvent) → void
Parameters

event – FocusOutsideEvent

Returns
void
onInteractOutside?(event: InteractOutsideEvent) → void

Function called when an interaction happens outside the component.

Type
(event: InteractOutsideEvent) → void
Parameters

event – InteractOutsideEvent

Returns
void
onPointerDownOutside?(event: PointerDownOutsideEvent) → void

Function called when the pointer is pressed down outside the component.

Type
(event: PointerDownOutsideEvent) → void
Parameters

event – PointerDownOutsideEvent

Returns
void
onRequestDismiss?(event: LayerDismissEvent) → void

Function called when this layer is closed due to a parent layer being closed.

Type
(event: LayerDismissEvent) → void
Parameters

event – LayerDismissEvent

Returns
void
persistentElements?Array<() → Element | null>

Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event

Type
Array<() → Element | null>
portalled?boolean

Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.

Default
true
positioning?object

The user provided options used to position the popover content.

Type
{ restoreStyles?: boolean; applyStyles?: boolean; hideWhenDetached?: boolean; strategy?: "absolute" | "fixed"; placement?: Placement; offset?: { mainAxis?: number; crossAxis?: number; }; gutter?: number; shift?: number; overflowPadding?: number; arrowPadding?: number; flip?: boolean | Placement[]; slide?: boolean; overlap?: boolean; sameWidth?: boolean; fitViewport?: boolean; sizeMiddleware?: boolean; boundary?: (() → Boundary) | Boundary | "clipping-ancestors"; listeners?: boolean | AutoUpdateOptions; onComplete?: (data: ComputePositionReturn) → void; onPositioned?: ((data: { placed: boolean; }) → void); getAnchorElement?: () → HTMLElement | VirtualElement | null; getAnchorRect?: (element: HTMLElement | VirtualElement | null) → AnchorRect | null; updatePosition?: ((data: { updatePosition: () → Promise<void>; floatingElement: HTMLElement | null; }) → void | Promise<void>) }
Default
{ gutter: 6, placement: "bottom-start" }
present?boolean

Whether the node is present (controlled by the user).

restoreFocus?boolean

Whether to restore focus to the element that had focus before the popover was opened.

Default
true
skipAnimationOnMount?boolean

Whether to allow the initial presence animation.

Default
false
translations?object

Specifies the localized strings that identifies the accessibility elements and their states.

Type
{ closeTriggerLabel?: string }
unmountOnExit?boolean

Whether to unmount on exit. Ark default: false.

Default
true
className?string

Merged with the part's classes.

<button> data-slot="navigation-menu-trigger"

PropType
value?string

The value that identifies this specific trigger.

asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

AttributeType
data-current?string

Present when current.

data-placement?string

The placement of the trigger.

data-side?string

The side of the trigger that the trigger is positioned on.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
data-value?string

The value of the item.

<div> data-slot="navigation-menu-positioner"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

AttributeType
data-has-nested?string

Present when the positioner has nested popovers.

data-nested?string

Present when the positioner is nested within another popover.

CSS variableType
--available-heightstring

The available height in viewport.

--available-widthstring

The available width in viewport.

--reference-heightstring

The height of the root.

--reference-widthstring

The width of the reference element.

--transform-originstring

The transform origin for animations.

--xstring

The x position for transform.

--ystring

The y position for transform.

--z-indexstring

The z-index value.

<div> data-slot="navigation-menu-content"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

AttributeType
data-expanded?string

Present when expanded.

data-has-nested?string

Present when another popover is nested inside it.

data-nested?string

Present when it's nested inside another popover.

data-placementstring

The placement of the content.

data-side"top" | "right" | "bottom" | "left"

The side of the trigger that the content is positioned on.

Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
CSS variableType
--layer-indexstring

The index of the dismissable in the layer stack.

--nested-layer-countstring

The number of nested popovers.

--transform-originstring

Where the content scales from, on its trigger's side.

<ul> data-slot="navigation-menu-list"

PropType
className?string

Merged with the part's classes.

<a> data-slot="navigation-menu-link"

PropType
closeOnClick?boolean

Close the panel the link sits in when it's clicked. A click that opens * the link in a new tab (⌘ or Ctrl held) leaves the panel open. * * @default true.

Default
true
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

<div> data-slot="navigation-menu-indicator"

PropType
className?string

Merged with the part's classes.

<div> data-slot="navigation-menu-viewport"

PropType
className?string

Merged with the part's classes.