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.
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
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/navigation-menu.tsx:
- Update the import paths to match your project.
Usage
Give each item with content a value so the menu can be opened by default or controlled with value, defaultValue and onValueChange on the root. The root also accepts align for the popover and anchor for either layout; in panel layout, pass a ref to the full-width bar as anchor so the panel spans its width.
To style a top-level link like a trigger, pass navigationMenuTriggerStyle() as its className. Set active on a link to mark the current page.
Examples
By default
A menu that opens the Products item on mount with defaultValue.
Links only
A bar of plain links styled like triggers, with the first marked active.
Panel
The panel layout anchored to a sticky header, with columns of labelled links and large primary links.
API Reference
NavigationMenu
The root that manages open state and renders the popover or panel popup.
| Prop | Type | Default | Description |
|---|---|---|---|
layout | "popover" | "panel" | "popover" | Chooses the popup style: popover for a floating card, or panel for a full-width sheet with a backdrop. |
Also accepts the props of the primitive parts it wraps.
NavigationMenuList
The horizontal list of top-level items.
Also accepts the props of React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.List>.
NavigationMenuItem
One top-level entry, holding a trigger with content or a single link.
Also accepts the props of React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.Item>.
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.
Also accepts the props of the primitive part it wraps.
NavigationMenuPanel
The full-width sheet and backdrop used by the panel layout.
Also accepts the props of the primitive part it wraps.
NavigationMenuLink
A navigation link, either in the bar or inside content.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "lg" | "default" | Sets the link size; lg uses large, semibold text for primary destinations. |
Also accepts the props of the primitive part it wraps.
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 React.ComponentPropsWithRef<typeof NavigationMenuPrimitive.Icon>.
Accessibility
- Triggers are buttons with
aria-expandedreflecting 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
activeset receivesaria-current="page". - The trigger's caret icon is
aria-hidden.
Notes
- Styling hooks:
data-slotvalues such asnavigation-menu,navigation-menu-trigger,navigation-menu-content,navigation-menu-popup,navigation-menu-panel,navigation-menu-backdropandnavigation-menu-link. The root exposesdata-layout; links exposedata-sizeanddata-active. - Triggers and links restyle themselves automatically in the
panellayout, and panel list items animate in with a stagger that respects reduced motion. navigationMenuTriggerStyleis exported for styling links as triggers.- Uses the
popover,background,accentandprimarycolors, with a blurredbg-black/20backdrop (backdrop-blur-lg).