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 Primitive

Use Navigation Menu for top-level links and panels, such as the sections of a product site. Each trigger opens its panel in a shared space.

Anatomy

Use the Astro primitive adapter to render NavigationMenu anatomy with the Runtime wiring included.

---
import { NavigationMenu } from "@starwind-ui/astro/navigation-menu";
---
<NavigationMenu.Root>
<NavigationMenu.List>
<NavigationMenu.Item value="products">
<NavigationMenu.Trigger>
<NavigationMenu.Icon>v</NavigationMenu.Icon>
</NavigationMenu.Trigger>
<NavigationMenu.Content>
<NavigationMenu.Link href="/docs">Docs</NavigationMenu.Link>
</NavigationMenu.Content>
</NavigationMenu.Item>
</NavigationMenu.List>
<NavigationMenu.Portal>
<NavigationMenu.Positioner>
<NavigationMenu.Popup>
<NavigationMenu.Viewport />
<NavigationMenu.Arrow />
</NavigationMenu.Popup>
</NavigationMenu.Positioner>
</NavigationMenu.Portal>
</NavigationMenu.Root>

Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed packageโ€™s types for the available props and events. Plain HTML uses DOM events and Runtime methods.

Usage Guidelines

  • Use Navigation Menu for top-level site or product navigation. Use it when a row or column of triggers reveals rich panels that share one viewport.
  • Use Menu or Popover for isolated actions. Navigation Menu is value-driven and viewport-driven, so it is heavier than a single contextual popup.

Shared Viewport

Content panels are authored inside items, then moved into the shared viewport while active so the popup can animate size and direction consistently.

Floating Behavior

FactValue
Anchor parttrigger
Positioner partpositioner
Popup partpopup
Portal partportal
Option propsside, align, sideOffset, alignOffset, avoidCollisions, collisionPadding

API Reference

Root

The navigation landmark that owns the active value, orientation, hover timing, dismissal options, and Runtime instance.

Default element
nav
Discovery hook
data-sw-nav-menu
Role
-

Props

Prop Type Default Toggle
value string | null -
Description
Controls the active item value when a framework adapter owns state.
Kind
control
Targets
root
Full type
string | null
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-default-value
  • starwind:value-change
  • setValue
defaultValue string | null null
Description
Sets the initial uncontrolled active item value.
Kind
control
Targets
root
Full type
string | null
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-default-value
  • starwind:value-change
  • setValue
openDelay number 50
Description
Sets the default hover-open delay in milliseconds.
Kind
option
Targets
root, trigger
Full type
number
closeDelay number 50
Description
Sets the default hover-close delay in milliseconds.
Kind
option
Targets
root, trigger
Full type
number
closeOnEscape boolean true
Description
Closes Navigation Menu when Escape is pressed.
Kind
option
Targets
-
Full type
boolean
closeOnOutsideInteract boolean true
Description
Closes Navigation Menu when the user interacts outside it.
Kind
option
Targets
-
Full type
boolean
onValueChange (value: string | null, details: NavigationMenuValueChangeDetails) => void -
Description
Runs when the Navigation Menu value changes.
Kind
callback
Targets
-
Full type
(value: string | null, details: NavigationMenuValueChangeDetails) => void
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-default-value
  • starwind:value-change
  • setValue
orientation "horizontal" | "vertical" "horizontal"
Description
Sets horizontal or vertical trigger keyboard movement.
Kind
option
Targets
root
Full type
"horizontal" | "vertical"

Events

Event Callback Value Toggle
valueChange onValueChange value: string | null
Description
Fires when the value changes for Navigation Menu.
DOM event
starwind:value-change
Details type
NavigationMenuValueChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.

State

State Type Props Toggle
value string | null value / defaultValue
Description
Tracks the current Navigation Menu value.
Initial attribute
data-default-value
Runtime getter
getValue
Runtime setter
setValue
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-default-value
  • starwind:value-change
  • setValue

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu - Runtime discovery hook for the Navigation Menu root.
State
Attribute Value Description
data-state - Reflects whether any item is open.
Metadata
Attribute Value Description
data-value - Reflects the value prop on the Root part.
data-controlled-value - Reflects the controlled value prop on the Root part.
data-default-value - Initial uncontrolled active item value.
data-open-delay - Reflects the open delay prop on the Root part.
data-close-delay - Reflects the close delay prop on the Root part.
data-close-on-escape - Reflects the close on escape prop on the Root part.
data-close-on-outside-interact - Reflects the close on outside interact prop on the Root part.
data-orientation - Reflects the orientation prop on the Root part.

List

The list of selectable Navigation Menu items.

Default element
ul
Discovery hook
data-sw-nav-menu-list
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-list - Marks the List part so Starwind Runtime can find it.

Item

An interactive item inside the Navigation Menu collection.

Default element
li
Discovery hook
data-sw-nav-menu-item
Role
-

Props

Prop Type Default Toggle
value string -
Description
Controls the current Navigation Menu value.
Kind
option
Targets
item
Full type
string
React

Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.

  • value
  • defaultValue
  • onValueChange
Astro

Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.

  • value
  • defaultValue
  • starwind:value-change
  • setValue
Runtime / HTML

Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.

  • data-default-value
  • starwind:value-change
  • setValue

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-item - Marks the Item part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Item part.
Metadata
Attribute Value Description
data-value - Reflects the value prop on the Item part.

Trigger

The button or asChild control that opens, closes, and keyboard-targets a content panel.

Default element
button
Discovery hook
data-sw-nav-menu-trigger
Role
-

Props

Prop Type Default Toggle
openDelay number -
Description
Overrides root hover-open timing for this trigger.
Kind
option
Targets
root, trigger
Full type
number
closeDelay number -
Description
Overrides root hover-close timing for this trigger.
Kind
option
Targets
root, trigger
Full type
number
asChild boolean -
Description
Merges trigger behavior into the slotted child control.
Kind
rendering
Targets
trigger
Full type
boolean
disabled boolean false
Description
Prevents trigger interaction and removes it from roving trigger movement.
Kind
option
Targets
trigger
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-trigger - Runtime discovery hook for the trigger part.
State
Attribute Value Description
data-state - Reflects whether this trigger's item is open.
Metadata
Attribute Value Description
data-as-child - Reflects the as child prop on the Trigger part.
data-open-delay - Reflects the open delay prop on the Trigger part.
data-close-delay - Reflects the close delay prop on the Trigger part.
data-disabled - Reflects the disabled prop on the Trigger part.

Icon

Decorative icon rendered by Navigation Menu.

Default element
span
Discovery hook
data-sw-nav-menu-icon
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-icon - Marks the Icon part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Icon part.

Content

The authored item panel. The Runtime moves the active content into the shared viewport.

Default element
div
Discovery hook
data-sw-nav-menu-content
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-content - Runtime discovery hook for the content part.
State
Attribute Value Description
data-state - Reflects whether this content panel is active.

A navigation link inside content. Links close the active menu by default and can mark current-page state.

Default element
a
Discovery hook
data-sw-nav-menu-link
Role
-

Props

Prop Type Default Toggle
href string -
Description
Sets the href attribute on the Link part.
Kind
attribute
Targets
link
Full type
string
active boolean false
Description
Marks the link as active and sets aria-current.
Kind
option
Targets
link
Full type
boolean
closeOnClick boolean true
Description
Controls whether clicking the link closes the menu.
Kind
option
Targets
link
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-link - Runtime discovery hook for the link part.
Metadata
Attribute Value Description
data-active - Present when the link is active.
data-close-on-click - Set to false to keep the menu open after link activation.

Portal

Moves Navigation Menu overlay content to the document body when needed.

Default element
div
Discovery hook
data-sw-nav-menu-portal
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-portal - Marks the Portal part so Starwind Runtime can find it.
data-placement - Marks the Portal part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-container - Reflects the container prop on the Portal part.
data-disabled - Reflects the disabled prop on the Portal part.
data-sw-portal-placement runtime Identifies Portal metadata for styling and selectors.

Positioner

The floating positioning part for the shared popup.

Default element
div
Discovery hook
data-sw-nav-menu-positioner
Role
-

Props

Prop Type Default Toggle
side "top" | "right" | "bottom" | "left" "bottom"
Description
Sets the preferred side for the popup.
Kind
option
Targets
positioner
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
Description
Sets popup alignment relative to the active trigger.
Kind
option
Targets
positioner
Full type
"start" | "center" | "end"
sideOffset number 4
Description
Sets the distance between the popup and trigger.
Kind
option
Targets
positioner
Full type
number
alignOffset number 0
Description
Adjusts the cross-axis alignment offset for Navigation Menu content.
Kind
option
Targets
positioner
Full type
number
avoidCollisions boolean true
Description
Allows the popup to shift or flip to remain visible.
Kind
option
Targets
positioner
Full type
boolean
collisionPadding number 8
Description
Configures the collision padding option for the Positioner part.
Kind
option
Targets
positioner
Full type
number

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-positioner - Runtime discovery hook for the positioner part.
State
Attribute Value Description
data-state - Reflects the current state on the Positioner part.
Metadata
Attribute Value Description
data-side - Reflects the resolved floating side.
data-align - Reflects the resolved floating alignment.
data-side-offset - Reflects the side offset prop on the Positioner part.
data-align-offset - Reflects the align offset prop on the Positioner part.
data-avoid-collisions - Reflects the avoid collisions prop on the Positioner part.
data-collision-padding - Reflects the collision padding prop on the Positioner part.

The floating content container for Navigation Menu.

Default element
div
Discovery hook
data-sw-nav-menu-popup
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-popup - Marks the Popup part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Popup part.

Viewport

The shared visible container that receives active item content and carries measured size state.

Default element
div
Discovery hook
data-sw-nav-menu-viewport
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-viewport - Runtime discovery hook for the viewport part.
State
Attribute Value Description
data-state - Reflects whether any content is visible.

Arrow

The arrow element that visually points to the trigger.

Default element
div
Discovery hook
data-sw-nav-menu-arrow
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-nav-menu-arrow - Marks the Arrow part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Arrow part.

Runtime API

Factory
createNavigationMenu
Import
@starwind-ui/runtime/navigation-menu
Root hook
root data-sw-nav-menu
Option props
closeDelay, closeOnEscape, closeOnOutsideInteract, defaultValue, onValueChange, openDelay, value

Option Lifecycles

OptionLifecycle
closeDelayconstructor-only
closeOnEscapeconstructor-only
closeOnOutsideInteractconstructor-only
defaultValueconstructor-only
onValueChangeconstructor-only
openDelayconstructor-only
valuesetter-backed

Runtime Setters

Method Target Description
setValue state: value Updates the current Navigation Menu value from Runtime code.
Component Relationship
Navigation Menu Direct primitive

Changelog

View version history v1.3.0 7 releases

v1.3.0

  • Navigation Menu trigger keys follow visible horizontal order. Menus that move into a portal keep the direction of their trigger.
  • Navigation Menu now returns focus without scrolling the page. Before, in Safari, closing its content after scrolling could make the page jump back to the trigger.
  • 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.
  • The positioner now sets `--sw-floating-arrow-x` for a top or bottom side and `--sw-floating-arrow-y` for a left or right side when the Navigation Menu arrow has a width and a height. These values point the arrow at the center of the trigger when the arrow can reach it. Otherwise the arrow points at the nearest part of the trigger. The arrow stays inside the popup, at least 6px from each end. Each value is the distance from the left or top edge of the popup to the same edge of the arrow, in RTL too. To use it, position a custom arrow absolutely inside the popup, set `left: var(--sw-floating-arrow-x)` or `top: var(--sw-floating-arrow-y)`, and remove any centering transform on that axis.
  • In Svelte, the `children` snippet of `NavigationMenu.Root` no longer receives arguments. If you read the value from a snippet argument, use `bind:value` on the root instead.
  • In Vue, this Primitive now uses the same `asChild` child handling as the other Vue Primitives. Its public API is unchanged. An invalid `asChild` child now gives one shorter error message.
  • In React and Vue, a Navigation Menu with a `defaultValue` no longer opens again after the user closes it and a prop on its Root changes.
  • In Svelte, the server HTML of `NavigationMenu.Root` now prints `data-default-value`, as in the other frameworks.
  • 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.2.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 Astro, an attribute that you set on a Navigation Menu part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.
  • 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.
  • In Svelte, `NavigationMenu.Popup` no longer takes `side` or `align`. Set them on `NavigationMenu.Positioner`.
  • In Vue, the template ref of the Navigation Menu root no longer has the undocumented methods `open`, `close`, `updatePosition`, `getValue`, and `setValue`. It exposes only `element`. Use `v-model` on the root instead.
  • Navigation Menu no longer moves focus back to its trigger when you move to another control while it closes.
  • In Vue, Navigation Menu now moves keyboard focus into its content when you use `v-model`.
  • In Svelte, the Navigation Menu 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.1.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.
  • Reduced background work when a Vue page uses multiple menus, tooltips, or other portals.
  • 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.
  • Reduced repeated JavaScript when Astro Navigation Menu is used with other Starwind components.
  • Reduced JavaScript used by Svelte Navigation Menu. Element props, event handlers, and refs keep the same behavior.

v1.1.0

  • Added `container` and `disabled` to the Portal part. `container` sets the element that holds the popup, and `disabled` keeps the popup in place. Portals now place nested popups in the same way every time, and they show their placement in data attributes.

v1.0.0

  • This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.

v0.1.1

  • The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.

v0.1.0

  • First release. Navigation Menu tracks the open item and supports the keyboard. It moves its indicator and shows the panels in one shared area.