NavigationMenu
The main navigation of a site, with sections that open a panel of links below the bar.
A navigation menu is the top navigation of a website: a bar of sections, each opening a panel with its links, and plain links beside them. It is for moving between pages. For commands, use a menubar or a dropdown menu; for the navigation of an application, a sidebar.
// apps/docs/examples/ui/navigation-menu.tsx'use client';
import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger,} from '@workspace/active-ui/components/primitives/navigation-menu';
// Invented sections; the links point to anchors, nothing navigates.const SECTIONS = [ { trigger: 'Pension', links: [ {title: 'Participants', description: 'Active and deferred members.'}, {title: 'Schemes', description: 'Accrual rules per scheme.'}, {title: 'Calculations', description: 'Batches and their results.'}, ], }, { trigger: 'Relations', links: [ {title: 'Persons', description: 'The register of people.'}, {title: 'Organisations', description: 'Employers and providers.'}, ], },] as const;
const anchor = (title: string) => `#nav-${title.toLowerCase().replaceAll(' ', '-')}`;
/** * The main navigation of a site: sections whose links open in a panel below * the bar, and a plain link beside them. Moving from one section to the * next keeps the panel open and slides it to the new content. */export default function NavigationMenuExample() { return ( <NavigationMenu aria-label="Main"> <NavigationMenuList> {SECTIONS.map((section) => ( <NavigationMenuItem key={section.trigger}> <NavigationMenuTrigger>{section.trigger}</NavigationMenuTrigger> <NavigationMenuContent> <ul className="grid w-72 gap-1"> {section.links.map((link) => ( <li key={link.title}> <NavigationMenuLink href={anchor(link.title)} className="flex-col items-start gap-0.5" > <span className="font-medium">{link.title}</span> <span className="text-muted-foreground"> {link.description} </span> </NavigationMenuLink> </li> ))} </ul> </NavigationMenuContent> </NavigationMenuItem> ))} <NavigationMenuItem> <NavigationMenuLink href={anchor('Reports')}> Reports </NavigationMenuLink> </NavigationMenuItem> </NavigationMenuList> </NavigationMenu> );}Usage#
import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger,} from '@workspace/active-ui/components/primitives/navigation-menu';
<NavigationMenu aria-label="Main"> <NavigationMenuList> <NavigationMenuItem> <NavigationMenuTrigger>Pension</NavigationMenuTrigger> <NavigationMenuContent> <NavigationMenuLink href="/participants"> Participants </NavigationMenuLink> </NavigationMenuContent> </NavigationMenuItem> </NavigationMenuList></NavigationMenu>;Anatomy#
Navigation: theMenu <nav>.align(defaultstart) places the panel under its trigger. It renders the panel's positioner itself.Navigationwith aMenu List Navigationper section or link.Menu Item NavigationandMenu Trigger Navigation: a section and its panel. Moving between triggers with a panel open slides the panel to the new content.Menu Content Navigation: a link, in a panel or directly in the list.Menu Link rendermakes your router's link the element.navigationgives another element the look of a trigger.Menu Trigger Style() Navigation: the positioner of the panel, whichMenu Positioner Navigationrenders itself.Menu Navigation: an optional pointer, a small rotated square, for a trigger of your own design; the menu does not render it.Menu Indicator
What your application provides#
A name for the
<nav>(aria-), the sections and their links.label The current page: give its link
active, which marks it (data-).active
Accessibility and keyboard#
Tabmoves through the triggers and links;Enter,Spaceorโopens a panel andTabcontinues into its links.Escapecloses the panel and returns the focus to its trigger.On a small screen, a bar of panels needs room it does not have: offer the same links in a sheet or a drawer instead.
API#
NavigationMenu#
Import from @workspace/
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Other parts#
NavigationMenuContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
NavigationMenuItem
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
NavigationMenuLink
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
NavigationMenuTrigger
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
NavigationMenuPositioner
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Parts that take only their elementโs attributes
Functions, hooks and constants
This page adapts the Navigation Menu documentation of shadcn/ui (MIT licence) to this package; see Third-party notices.