Prototyper UI

Navigation Menu

site navigation component with dropdown menus on Base UI

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/navigation-menu.json
npx shadcn@latest add https://prototyper-ui.com/r/navigation-menu.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/navigation-menu.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/navigation-menu.json

This will add the following files to your project:

  • components/ui/navigation-menu.tsx

Usage

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

<NavigationMenu>
  <NavigationMenuList>
    <NavigationMenuItem>
      <NavigationMenuTrigger>Item One</NavigationMenuTrigger>
      <NavigationMenuContent>
        <NavigationMenuLink href="/docs">
          Documentation
        </NavigationMenuLink>
      </NavigationMenuContent>
    </NavigationMenuItem>
    <NavigationMenuItem>
      <NavigationMenuLink href="/about">About</NavigationMenuLink>
    </NavigationMenuItem>
  </NavigationMenuList>
</NavigationMenu>

Anatomy

<NavigationMenu>
  <NavigationMenuList>
    <NavigationMenuItem>
      <NavigationMenuTrigger />
      <NavigationMenuContent>
        <NavigationMenuLink />
      </NavigationMenuContent>
    </NavigationMenuItem>
  </NavigationMenuList>
</NavigationMenu>
Sub-componentdata-slotPurposeRequired
NavigationMenunavigation-menuRoot provider, manages open state and renders the positionerYes
NavigationMenuListnavigation-menu-listContainer for menu itemsYes
NavigationMenuItemnavigation-menu-itemWraps a single trigger + content pair or a standalone linkYes
NavigationMenuTriggernavigation-menu-triggerButton that opens a dropdown content areaNo
NavigationMenuContentnavigation-menu-contentDropdown panel associated with a triggerNo
NavigationMenuLinknavigation-menu-linkLink item inside the content or used standaloneNo
NavigationMenuPositionernavigation-menu-positionerPositions the popup relative to the trigger (rendered by root)Auto
NavigationMenuIndicatornavigation-menu-indicatorOptional visual indicator arrowNo

Examples

With Dropdowns

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the navigation menu:

Slot nameElement
navigation-menuRoot wrapper
navigation-menu-listContainer for items
navigation-menu-itemIndividual item wrapper
navigation-menu-triggerTrigger button that opens content
navigation-menu-contentDropdown content panel
navigation-menu-linkLink inside content or standalone
navigation-menu-positionerFloating positioner element
navigation-menu-popupPopup container within the positioner
navigation-menu-viewportViewport inside the popup
navigation-menu-indicatorOptional indicator arrow
navigation-menu-indicator-arrowArrow element inside the indicator

Customization Examples

/* Wider dropdown content */
[data-slot="navigation-menu-content"] {
  @apply p-4;
}

/* Custom trigger active state */
[data-slot="navigation-menu-trigger"][data-popup-open] {
  @apply bg-primary text-primary-foreground;
}
{/* Style the navigation menu list with additional gap */}
<NavigationMenuList className="gap-1">
  <NavigationMenuItem>
    <NavigationMenuTrigger>Item</NavigationMenuTrigger>
    <NavigationMenuContent>...</NavigationMenuContent>
  </NavigationMenuItem>
</NavigationMenuList>

API Reference

Root component that manages navigation state and renders the popup positioner.

Prop

Type

All Base UI NavigationMenu.Root props are forwarded via ...props.

Container for navigation menu items.

Prop

Type

All Base UI NavigationMenu.List props are forwarded via ...props.

Wraps a trigger + content pair or a standalone link.

Prop

Type

All Base UI NavigationMenu.Item props are forwarded via ...props.

Button that opens the associated dropdown content.

Prop

Type

All Base UI NavigationMenu.Trigger props are forwarded via ...props.

Dropdown panel shown when its associated trigger is activated.

Prop

Type

All Base UI NavigationMenu.Content props are forwarded via ...props.

A link element inside the navigation menu. Can be used within content dropdowns or as a standalone item.

Prop

Type

All Base UI NavigationMenu.Link props are forwarded via ...props.

Controls the position of the popup. Rendered automatically by NavigationMenu; you do not need to add it manually.

Prop

Type

Optional visual indicator arrow displayed below the active trigger.

Prop

Type

All Base UI NavigationMenu.Icon props are forwarded via ...props.

A cva helper exported for use outside of the <NavigationMenuTrigger> component (e.g., applying trigger styles to standalone links).

import { navigationMenuTriggerStyle } from "@/components/ui/navigation-menu"

<NavigationMenuLink href="/docs" className={navigationMenuTriggerStyle()}>
  Documentation
</NavigationMenuLink>

Accessibility

Keyboard Interactions

KeyAction
SpaceOpens the dropdown when a trigger is focused
EnterOpens the dropdown when a trigger is focused, activates links
ArrowDownOpens the dropdown from a trigger; moves focus within content
ArrowUpMoves focus within content
ArrowRightMoves focus to the next trigger in the list
ArrowLeftMoves focus to the previous trigger in the list
HomeMoves focus to the first trigger
EndMoves focus to the last trigger
EscapeCloses the open dropdown and returns focus to the trigger
TabMoves focus out of the navigation menu, closing any open dropdown

ARIA Attributes

  • The root element renders with role="navigation".
  • Each trigger renders with aria-expanded and aria-haspopup attributes.
  • The content panel is linked to its trigger via aria-controls.
  • Links render with role="link".
  • Active links can be marked with data-active="true" for aria-current behavior.

On this page