Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Navigation Menu

Navigation Menu provides Runtime-backed navigation disclosure, focus management, and floating content positioning.

Installation

Usage

---
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/starwind/navigation-menu";
---
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem value="item-one">
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink href="/docs/">Link</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>

Composition

Use the following composition to build a NavigationMenu:

NavigationMenu
└── NavigationMenuList
├── NavigationMenuItem
│ ├── NavigationMenuTrigger
│ └── NavigationMenuContent
│ ├── NavigationMenuLink
│ └── NavigationMenuLink
└── NavigationMenuItem
└── NavigationMenuLink

Sizes

NavigationMenu defaults to size="md". Set size once to keep native triggers, List spacing, trigger-style Links, and portaled content aligned. Use contentSize only when the shared popup should intentionally use a different size.

Custom triggers

Native NavigationMenuTrigger elements merge ordinary class customization through their full recipe. With asChild, the child instead owns its complete appearance and markup; Navigation Menu adds behavior, accessibility/state attributes, and the Trigger’s consumer-provided class.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Navigation Menu

Inherits nav attributes. Omits `defaultValue`, `onChange`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
align "start" | "center" | "end" "start"
Description
Aligns the component within its available axis.
Classification
Wrapper prop
alignOffset number 0
Description
Offsets the component from its selected alignment in pixels.
Classification
Wrapper prop
avoidCollisions boolean true
Description
Repositions floating content to keep it inside the collision boundary.
Classification
Wrapper prop
collisionPadding number 8
Description
Sets the minimum space retained around a collision boundary.
Classification
Wrapper prop
contentSize "sm" | "md" size
Description
Sets the independently portaled popup content size and defaults to the resolved Navigation Menu size.
Classification
Wrapper prop
disablePortal boolean false
Description
Keeps the public Portal wrapper inline instead of moving it to a target.
Classification
Wrapper prop
portalContainer string —
Description
Sets the CSS selector for the public Portal wrapper target.
Classification
Wrapper prop
side "top" | "right" | "bottom" | "left" "bottom"
Description
Selects the preferred side for floating content.
Classification
Wrapper prop
sideOffset number 8
Description
Sets the distance in pixels between floating content and its anchor.
Classification
Wrapper prop
size "sm" | "md" "md"
Description
Sets the visual size of native styled triggers, List spacing, indicators, and top-level Links using navigationMenuTriggerStyle().
Classification
Wrapper prop

Navigation Menu Item

Inherits li attributes.

Contains the following additional props:

Prop Type Default Toggle details
value string —
Description
Controls or identifies the component value.
Classification
Wrapper prop

Navigation Menu Trigger

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Delegates markup and complete visual ownership to the child while retaining Navigation Menu behavior and accessibility wiring.
Classification
Primitive override
Primitive prop
navigation-menu.Trigger.asChild
closeDelay number —
Description
Sets the delay in milliseconds before closing.
Classification
Primitive override
Primitive prop
navigation-menu.Trigger.closeDelay
iconClass string —
Description
Adds classes to the component's generated icon.
Classification
Wrapper prop
openDelay number —
Description
Sets the delay in milliseconds before opening.
Classification
Primitive override
Primitive prop
navigation-menu.Trigger.openDelay
showIcon boolean true
Description
Shows the component's generated icon.
Classification
Wrapper prop

Navigation Menu Positioner

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
disablePortal boolean false
Description
Keeps the public Portal wrapper inline instead of moving it to a target.
Classification
Wrapper prop
portalContainer string —
Description
Sets the CSS selector for the public Portal wrapper target.
Classification
Wrapper prop
sideOffset number 8
Description
Sets the distance in pixels between floating content and its anchor.
Classification
Primitive override
Primitive prop
navigation-menu.Positioner.sideOffset
size "sm" | "md" "md"
Description
Sets the popup content size when rendering NavigationMenuPositioner directly.
Classification
Wrapper prop

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Navigation Menu.

Runtime API

Navigation Menu primitive
createNavigationMenu from @starwind-ui/runtime/navigation-menu

Changelog

View version history v1.4.0 7 releases

v1.4.0

  • Navigation Menu trigger keys and indicators follow the visible direction. Its popup keeps the direction of its trigger when it moves into a portal.
  • A click during the Navigation Menu close animation now goes to the page below the popup. Before, the closing popup caught the click, so a quick click on a control under it did nothing.
  • When you close a Navigation Menu with Escape, focus now goes back to the trigger as the close starts. The closing menu takes no keyboard input until it hides.
  • Navigation Menu now stays on screen when its trigger is at the edge of the screen, for example on a phone. Before, the popup kept its alignment, so part of it went off screen. Now the popup moves along its trigger until it is inside the viewport padding. It stays next to the trigger and keeps its side.
  • Navigation Menu content with no set width now takes the width of its links. Before, it filled the full width of the screen. The content is never wider than the screen minus 2rem. To set a width, add a width class to NavigationMenuContent.
  • In Svelte, the children snippet of NavigationMenu no longer receives arguments. If you read the value from a snippet argument, use bind:value instead.
  • Update copied NavigationMenu.svelte files with starwind update navigation-menu. The old files pass the removed arguments.
  • In React and Vue, a Navigation Menu with a defaultValue no longer opens again after the user closes it and a prop on it changes.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v1.3.0

  • Fixed a Navigation Menu panel that flashed and closed when you moved the mouse to a trigger and clicked it. A click that starts within 500 ms after hover opened the panel now keeps it open. A second click, a later click, the keyboard, and touch still close it.
  • In Svelte, a defined value that you pass when NavigationMenu mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, NavigationMenu keeps its own state. The first render now follows the initial value.
  • NavigationMenu no longer moves focus back to its trigger when you move to another control while it closes.
  • In Vue, NavigationMenu now moves keyboard focus into its content when you use v-model.
  • In Svelte, the NavigationMenu trigger now accepts a link in child. Before, it warned in development, type checks rejected the link, and ref did not run. Use the new TriggerChildPayload type for your snippet.

v1.2.1

  • Fixed links after menu content moves into the shared viewport. They follow your close-on-select settings and affect the correct menu when menus are nested.
  • Reduced background work when a React page uses multiple menus, tooltips, or other portals.
  • Fixed nested Svelte overlays inside a dialog appearing behind their parent or failing to receive clicks.
  • Fixed nested overlays appearing behind their parent in Vue and Svelte. Overlays can now render under the document body; if custom CSS or DOM queries require them to stay inside a parent, set a portal container or add data-floating-root to that parent.
  • Fixed React handling of menu content added to or removed from the shared viewport.
  • Fixed React 18 retaining removed popup elements when the parent component stays mounted.

v1.2.0

  • Added portalContainer and disablePortal to NavigationMenu and NavigationMenuPositioner for custom portal targets and inline rendering.

v1.1.1

  • The default export in index.ts now has a name, NavigationMenuParts, so framework tools show a clear name.

v1.1.0

  • Added sm and md sizes on the root, and contentSize for the shared popup, which renders in a portal. If you leave out contentSize, the popup uses the root size.
  • With asChild, NavigationMenuTrigger now keeps the look and markup of your child element. Style and size the child yourself, and add an icon inside it if you want one. Navigation Menu still adds the behavior and the accessibility attributes.

v1.0.0

  • Added Navigation Menu, with keyboard navigation and one shared area that shows the open panel. It gets its behavior from Starwind Runtime.
  • See the Navigation Menu Primitive for the unstyled parts and the behavior API.