Demos

Two menus with panels and a plain link.

Usage

Use a navigation menu for the main links of a site header. Each item is either a trigger that opens a panel of links, or a link on its own. For actions on the current page, such as an account menu with "Sign out", use a dropdown menu.

Import it from @workspace/ui/components/navigation-menu.

Anatomy

  • NavigationMenu — The root. Renders a nav and the shared popup that holds every panel.
  • NavigationMenuList — The row of items.
  • NavigationMenuItem — One item in the row.
  • NavigationMenuTrigger — Opens the item's panel on hover, focus or click. Shows a chevron that turns when open.
  • NavigationMenuContent — The panel. Its contents move into the shared popup, which resizes between panels.
  • NavigationMenuLink — A link, inside a panel or on its own in the row.
  • navigationMenuTriggerStyle — Classes that make a NavigationMenuLink in the row match the triggers.

Notes

  • Give each panel a width, for example w-72 on the list inside NavigationMenuContent. The popup sizes itself to the open panel.
  • To use a router link such as next/link, pass it to render: <NavigationMenuLink render={<Link href="/pricing" />}>Pricing</NavigationMenuLink>.
  • Set active on the link for the current page. It sets aria-current="page" and data-active for styling.
  • The menu does not collapse on small screens. Hide it below a breakpoint and show the links in a sheet instead, as the header block does.

Examples

With icon

Put an icon before the label. Icons are sized to size-4 unless you set a size.

Links on their own, with no panels. The first link is active.

Props

These are the props you set most often. Unlisted props pass through to the underlying Base UI part.

PropTypeDefaultDescription
align"start" or "center" or "end""start"How the popup lines up with the open trigger.
valueany—Value of the open item, when controlled.
defaultValueanynullValue of the item open at first.
onValueChange(value) => void—Called when an item opens or closes.
delaynumber50Milliseconds of hover before a panel opens.
closeDelaynumber50Milliseconds before a panel closes after the pointer leaves.
classNamestring—Classes merged onto the root.
PropTypeDefaultDescription
hrefstring—Where the link goes.
activebooleanfalseWhether the link is the current page.
closeOnClickbooleanfalseWhether clicking closes the menu.
renderReactElement—Element to render instead of a, such as a router link.