NavigationMenu Primitive
Navigation Menu coordinates a single active top-level item, shared viewport content, hover timing, keyboard movement, and link close behavior for site navigation.
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.
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>Use the React primitive adapter when NavigationMenu state participates in React rendering.
import { NavigationMenu } from "@starwind-ui/react/navigation-menu";
export function Example() { return ( <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> );}Render the NavigationMenu data-sw-* contract yourself, then initialize createNavigationMenu.
<nav data-sw-nav-menu> <ul data-sw-nav-menu-list> <li data-sw-nav-menu-item data-value="products"> <button data-sw-nav-menu-trigger type="button" aria-haspopup="menu"> <span data-sw-nav-menu-icon aria-hidden="true">v</span> </button> <div data-sw-nav-menu-content hidden> <a data-sw-nav-menu-link href="/docs">Docs</a> </div> </li> </ul> <div data-sw-nav-menu-portal> <div data-sw-nav-menu-positioner> <div data-sw-nav-menu-popup hidden> <div data-sw-nav-menu-viewport hidden></div> <div data-sw-nav-menu-arrow aria-hidden="true"></div> </div> </div> </div></nav>
<script type="module"> import { createNavigationMenu } from "@starwind-ui/runtime/navigation-menu";
const root = document.querySelector("[data-sw-nav-menu]"); if (root) { createNavigationMenu(root); }</script>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
| Fact | Value |
|---|---|
| Anchor part | trigger |
| Positioner part | positioner |
| Popup part | popup |
| Portal part | portal |
| Option props | side, 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
value string | null -
- Description
- Controls the active item value when a framework adapter owns state.
- Kind
- control
- Targets
- root
- Full type
- string | null
defaultValue string | null null
- Description
- Sets the initial uncontrolled active item value.
- Kind
- control
- Targets
- root
- Full type
- string | null
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 NavigationMenu when Escape is pressed.
- Kind
- option
- Targets
- -
- Full type
- boolean
closeOnOutsideInteract boolean true
- Description
- Closes NavigationMenu when the user interacts outside it.
- Kind
- option
- Targets
- -
- Full type
- boolean
onValueChange (value: string | null, details: NavigationMenuValueChangeDetails) => void -
- Description
- Runs when the NavigationMenu value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: string | null, details: NavigationMenuValueChangeDetails) => void
orientation "horizontal" | "vertical" "horizontal"
- Description
- Sets horizontal or vertical trigger keyboard movement.
- Kind
- option
- Targets
- root
- Full type
- "horizontal" | "vertical"
Events
valueChange onValueChange value: string | null
- Description
- Fires when the value changes for NavigationMenu.
- DOM event
- starwind:value-change
- Details type
- NavigationMenuValueChangeDetails
- Timing
- before-state-commit
- Cancelable
- Yes
State
value string | null value / defaultValue
- Description
- Tracks the current NavigationMenu value.
- Initial attribute
- data-default-value
- Runtime getter
- getValue
- Runtime setter
- setValue
- State control support
- React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-default-value, emits starwind:value-change, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.
Data Attributes
Runtime hooks
State
Metadata
List
The list of selectable NavigationMenu items.
- Default element
- ul
- Discovery hook
- data-sw-nav-menu-list
- Role
- -
Data Attributes
Runtime hooks
Item
An interactive item inside the NavigationMenu collection.
- Default element
- li
- Discovery hook
- data-sw-nav-menu-item
- Role
- -
Props
value string -
- Description
- Controls the current NavigationMenu value.
- Kind
- option
- Targets
- item
- Full type
- string
Data Attributes
Runtime hooks
State
Metadata
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
openDelay number 50
- Description
- Overrides root hover-open timing for this trigger.
- Kind
- option
- Targets
- root, trigger
- Full type
- number
closeDelay number 50
- 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
State
Metadata
Icon
Decorative icon rendered by NavigationMenu.
- Default element
- span
- Discovery hook
- data-sw-nav-menu-icon
- Role
- -
Data Attributes
Runtime hooks
State
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
State
Link
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
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
Metadata
Portal
Moves NavigationMenu overlay content to the document body when needed.
- Default element
- div
- Discovery hook
- data-sw-nav-menu-portal
- Role
- -
Data Attributes
Runtime hooks
Positioner
The floating positioning part for the shared popup.
- Default element
- div
- Discovery hook
- data-sw-nav-menu-positioner
- Role
- -
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for the popup.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets popup alignment relative to the active trigger.
- Kind
- option
- Targets
- positioner, popup
- 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 NavigationMenu 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
State
Metadata
Popup
The floating content container for NavigationMenu.
- Default element
- div
- Discovery hook
- data-sw-nav-menu-popup
- Role
- -
Props
side "top" | "right" | "bottom" | "left" "bottom"
- Description
- Sets the preferred side for NavigationMenu content.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "start"
- Description
- Sets how NavigationMenu content aligns to its trigger.
- Kind
- option
- Targets
- positioner, popup
- Full type
- "start" | "center" | "end"
Data Attributes
Runtime hooks
State
Metadata
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
State
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
State
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
| Option | Lifecycle |
|---|---|
| closeDelay | constructor-only |
| closeOnEscape | constructor-only |
| closeOnOutsideInteract | constructor-only |
| defaultValue | constructor-only |
| onValueChange | constructor-only |
| openDelay | constructor-only |
| value | setter-backed |