Navigation Menu

A navigation menu provides a clear visual structure for the primary links of a website or application. It is typically anchored to the top of the interface and includes triggers that reveal dropdown menus containing related sub-links.

This component is built on top of Base UI, ensuring it is fully accessible, supports keyboard navigation, and works seamlessly across different screen sizes.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add navigation-menu

Anatomy

Import the component parts and combine them to create a structured navigation menu.

import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  NavigationMenuIndicator,
  NavigationMenuPositioner
} from "@/registry/core/navigation-menu";

export const NavigationMenuExample = () => (
  <NavigationMenu>
    <NavigationMenuList>
      <NavigationMenuItem>
        <NavigationMenuTrigger>Item One</NavigationMenuTrigger>
        <NavigationMenuContent>
          <NavigationMenuLink href="/link1">Link One</NavigationMenuLink>
        </NavigationMenuContent>
      </NavigationMenuItem>
      <NavigationMenuItem>
        <NavigationMenuLink href="/link2">Direct Link Two</NavigationMenuLink>
      </NavigationMenuItem>
      <NavigationMenuIndicator />
    </NavigationMenuList>
    <NavigationMenuPositioner />
  </NavigationMenu>
);

Usage

Import the navigation menu components and compose them to build your menu structure. You can use NavigationMenuContent for dropdowns or NavigationMenuLink for direct links.

import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  NavigationMenuPositioner
} from "@/registry/core/navigation-menu";

export default function NavigationMenuExample() {
  return (
    <NavigationMenu>
      <NavigationMenuList>
        <NavigationMenuItem>
          <NavigationMenuTrigger>Products</NavigationMenuTrigger>
          <NavigationMenuContent>
            <NavigationMenuLink href="/analytics">Analytics</NavigationMenuLink>
          </NavigationMenuContent>
        </NavigationMenuItem>
        <NavigationMenuItem>
          <NavigationMenuLink href="/pricing">Pricing</NavigationMenuLink>
        </NavigationMenuItem>
      </NavigationMenuList>
      <NavigationMenuPositioner />
    </NavigationMenu>
  );
}

Examples

Simple Navigation Menu

A clean, text-based navigation menu with simple dropdown lists.

Positioning

Use the NavigationMenuPositioner component to position the viewport according to your need.

API Reference

The root component that manages the state of the navigation menu.

PropTypeDefaultDescription
defaultValueanynullThe uncontrolled value of the item that should be initially selected.
valueanynullThe controlled value of the navigation menu item that should be currently open.
onValueChange(value: any) => void-Callback fired when the value changes.
delaynumber50How long to wait before opening the navigation menu (ms).
closeDelaynumber50How long to wait before closing the navigation menu (ms).
orientation"horizontal" | "vertical""horizontal"The orientation of the navigation menu.
classNamestring-Additional CSS classes.

The container for the top-level menu items.

PropTypeDefaultDescription
childrenReact.ReactNode-NavigationMenuItem elements.
classNamestring-Additional CSS classes.

A single item in the navigation menu.

PropTypeDefaultDescription
valueany-A unique value that identifies this navigation menu item.
classNamestring-Additional CSS classes.

The button that opens the associated NavigationMenuContent.

PropTypeDefaultDescription
nativeButtonbooleantrueWhether the component renders a native <button> element.
classNamestring-Additional CSS classes.

An interactive link within the menu.

PropTypeDefaultDescription
hrefstring-The URL to link to.
activebooleanfalseWhether the link is the currently active page.
closeOnClickbooleanfalseWhether to close the navigation menu when the link is clicked.
classNamestring-Additional CSS classes.

The dropdown panel containing sub-links.

PropTypeDefaultDescription
keepMountedbooleanfalseWhether to keep the content mounted in the DOM while the popup is closed.
classNamestring-Additional CSS classes.

Positions the navigation menu against the currently active trigger.

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right""bottom"Which side of the anchor element to align the popup against.
sideOffsetnumber | function8Distance between the anchor and the popup in pixels.
align"start" | "center" | "end""start"How to align the popup relative to the specified side.
alignOffsetnumber | function0Additional offset along the alignment axis in pixels.
disableAnchorTrackingbooleanfalseWhether to disable tracking the layout shift of the anchor.
arrowPaddingnumber5Minimum distance between the arrow and the edge of the popup.
anchorElement | VirtualElement | React.RefObject<Element | null> | null-Explicit anchor element to position against. Positions to trigger if not provided.
collisionAvoidanceCollisionAvoidance Object-Determines how to handle collisions.
collisionBoundary'clipping-ancestors' | Element | Element[] | Rect'clipping-ancestors'Area that the popup is confined to.
collisionPaddingPadding Object | number5Additional space to maintain from the edge of the collision boundary.
stickybooleanfalseWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.
positionMethod'absolute' | 'fixed''absolute'CSS positioning method to use.
renderReactElement | function-Replaces the rendered component with a custom element.
classNamestring | function-Additional CSS classes.

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

PropTypeDefaultDescription
classNamestring-Additional CSS classes.

Accessibility

  • Built with Base UI: Ensures industry-standard accessible behaviors and keyboard navigation.
  • Keyboard Support: Full support for arrow keys to navigate between items, and Enter/Space to activate.
  • Focus Management: Focus is appropriately managed between the trigger and the dropdown content.
  • ARIA Roles: Uses proper ARIA roles like menubar, menuitem, and navigation out of the box.
  • Screen Readers: Correctly identifies expanding/collapsing states and active items for assistive technologies.