suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Navigation Menu

A site navigation bar whose items open popover or full-width panels of links.

Navigation Menu is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.

import {
  BookOpenIcon,
  ChartLineIcon,
  CodeIcon,
  LifebuoyIcon,
  LightningIcon,
  ShieldCheckIcon,
} from "@phosphor-icons/react"
import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,

Navigation Menu wraps the navigation menu primitive of the chosen base. NavigationMenu is the root; inside it, NavigationMenuList holds NavigationMenuItem entries. An item contains either a NavigationMenuTrigger with NavigationMenuContent, or a single NavigationMenuLink. Inside content, use NavigationMenuLabel for column headings and NavigationMenuLink for destinations.

The root renders the popup for you. With layout="popover" it adds a NavigationMenuPositioner, a floating card that resizes and slides between items. With layout="panel" it adds a NavigationMenuPanel, a full-width sheet under the bar with a blurred backdrop, like a store's global navigation. Use Navigation Menu for site navigation links; use Menubar or Dropdown Menu for commands.

Installation

$ pnpm dlx shadcn@latest add @esuiss/navigation-menu

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add navigation-menu
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react class-variance-authority
  1. Copy and paste the following code into your project.
components/ui/navigation-menu.tsx
"use client"

import { NavigationMenu as NavigationMenuPrimitive } from "@base-ui/react/navigation-menu"
import { CaretDownIcon } from "@phosphor-icons/react"
import { cva } from "class-variance-authority"
import { cn } from "@/lib/utils"

function NavigationMenu({
  align = "start",
  layout = "popover",
  anchor,
  className,
  children,
  ...props
}: NavigationMenuPrimitive.Root.Props &
  Pick<NavigationMenuPrimitive.Positioner.Props, "align" | "anchor"> & {
  1. Update the import paths to match your project setup.

Usage

import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"
<div className="flex min-h-96 items-start justify-center">
  <NavigationMenu align="start">
    <NavigationMenuList>
      <NavigationMenuItem value="products">
        <NavigationMenuTrigger>Products</NavigationMenuTrigger>
        <NavigationMenuContent>
          <ul className="grid w-96 gap-1">
            {products.map((product) => (
              <li key={product.title}>
                <NavigationMenuLink href="#" className="items-start gap-3">
                  <product.icon className="mt-0.5" />
                  <div className="flex flex-col gap-1">
                    <span className="font-medium">{product.title}</span>
                    <span className="text-muted-foreground">
                      {product.description}
                    </span>
                  </div>
                </NavigationMenuLink>
              </li>
            ))}
          </ul>
        </NavigationMenuContent>
      </NavigationMenuItem>
      <NavigationMenuItem value="resources">
        <NavigationMenuTrigger>Resources</NavigationMenuTrigger>
        <NavigationMenuContent>
          <ul className="grid w-56 gap-1">
            {resources.map((resource) => (
              <li key={resource.title}>
                <NavigationMenuLink href="#">
                  <resource.icon />
                  {resource.title}
                </NavigationMenuLink>
              </li>
            ))}
          </ul>
        </NavigationMenuContent>
      </NavigationMenuItem>
      <NavigationMenuItem>
        <NavigationMenuLink href="#" className={navigationMenuTriggerStyle()}>
          Pricing
        </NavigationMenuLink>
      </NavigationMenuItem>
    </NavigationMenuList>
  </NavigationMenu>
</div>

Composition

Use the following composition to build a NavigationMenu:

NavigationMenu
├── NavigationMenuList
│   └── NavigationMenuItem
│       ├── NavigationMenuTrigger
│       ├── NavigationMenuContent
│       │   ├── NavigationMenuLabel
│       │   └── NavigationMenuLink
│       └── NavigationMenuLink
├── NavigationMenuPositioner
└── NavigationMenuPanel

Examples

By default

Give each item with content a value, then set defaultValue on the root to open the Products item on mount.

import {
  BookOpenIcon,
  ChartLineIcon,
  CodeIcon,
  LifebuoyIcon,
  LightningIcon,
  ShieldCheckIcon,
} from "@phosphor-icons/react"
import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,

Links only

Pass navigationMenuTriggerStyle() as a link's className to style it like a trigger. Set active on the link for the current page.

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

export default function NavigationMenuLinksOnly() {
  return (
    <div className="flex min-h-96 items-start justify-center">
      <NavigationMenu align="start">
        <NavigationMenuList>
          <NavigationMenuItem>
            <NavigationMenuLink
              href="#"

Panel

Set layout="panel" and pass a ref to a sticky header as anchor so the panel spans its width. The columns use NavigationMenuLabel headings, and size="lg" links for primary destinations.

import * as React from "react"
import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLabel,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"

const panelMenus = [
  {
    value: "pos",
    label: "POS",

Accessibility

  • Triggers are buttons with aria-expanded reflecting whether their content is open.
  • Enter opens a focused trigger, and Tab moves focus into the open content.
  • Escape closes the open content and returns focus to its trigger.
  • Hovering another trigger switches the open content.
  • A link with active set receives aria-current="page".
  • The trigger's caret icon is aria-hidden.

API Reference

NavigationMenu

The root that manages open state and renders the popover or panel popup.

PropTypeDefault
layout"popover" | "panel""popover"
align"start" | "center" | "end""start"
PropTypeDefault
anchorElement | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null-
PropTypeDefault
anchorReact.RefObject<HTMLElement | null>-

Also accepts the props of the primitive parts it wraps.

layout="popover" shows a floating card, and layout="panel" a full-width sheet with a backdrop. align sets how the card lines up with the bar in the popover layout. anchor is the element the popup is positioned against; in the panel layout, pass a ref to the full-width bar. Give each item with content a value so the menu can be opened by default or controlled with value, defaultValue and onValueChange.

NavigationMenuList

The horizontal list of top-level items.

Also accepts the props of the primitive part it wraps.

NavigationMenuItem

One top-level entry, holding a trigger with content or a single link.

Also accepts the props of the primitive part it wraps.

NavigationMenuTrigger

The button that opens its item's content, with a caret in the popover layout.

Also accepts the props of the primitive part it wraps.

NavigationMenuContent

The content shown in the popup when its item is open.

Also accepts the props of the primitive part it wraps.

NavigationMenuPositioner

The floating popover card used by the popover layout. NavigationMenu renders it for you.

PropTypeDefault
side"top" | "right" | "bottom" | "left" | "inline-start" | "inline-end""bottom"
sideOffsetnumber8
align"start" | "center" | "end""start"
alignOffsetnumber0
PropTypeDefault
align"start" | "center" | "end""start"
anchorReact.RefObject<HTMLElement | null>-

Also accepts the props of the primitive part it wraps.

side is the side of the bar the card opens on, and sideOffset the gap in pixels between them. alignOffset shifts the card in pixels along the alignment axis.

anchor is the element the card is positioned against.

NavigationMenuPanel

The full-width sheet and backdrop used by the panel layout. NavigationMenu renders it for you.

PropTypeDefault
anchorReact.RefObject<HTMLElement | null>-

Also accepts the props of the primitive part it wraps.

NavigationMenuLink

A navigation link, either in the bar or inside content.

PropTypeDefault
size"default" | "lg""default"

Also accepts the props of the primitive part it wraps.

size="lg" uses large, semibold text for primary destinations. Set active to mark the current page. To style a top-level link like a trigger, pass navigationMenuTriggerStyle() as its className. Triggers and links restyle themselves in the panel layout, and panel list items animate in with a stagger that respects reduced motion.

NavigationMenuLabel

A small secondary heading above a group of links.

Also accepts the props of React.ComponentProps<"p">.

NavigationMenuIndicator

A small arrow that fades in while its menu is open.

Also accepts the props of the primitive part it wraps.

Each part sets a data-slot, such as navigation-menu-trigger or navigation-menu-panel, for styling. The root sets data-layout, and links set data-size and data-active.

NextPage IndicatorPreviousNative Select

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • By default
    • Links only
    • Panel
  5. 05Accessibility
  6. 06API Reference
    • NavigationMenu
    • NavigationMenuList
    • NavigationMenuItem
    • NavigationMenuTrigger
    • NavigationMenuContent
    • NavigationMenuPositioner
    • NavigationMenuPanel
    • NavigationMenuLink
    • NavigationMenuLabel
    • NavigationMenuIndicator