Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Navigation Menu for Astro

Astro navigation groups with links and optional popup panels.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/navigation-menu

Usage

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

Composition

Arrange the parts as shown for a NavigationMenu:

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

Notes

  • Keep inactive panels hidden in the initial HTML. The controller sets their visibility when it starts.

  • Put NavigationMenuIndicator in NavigationMenuList. Its position depends on measurements from that list.

  • Use NavigationMenuTrigger for items that open richer panels and NavigationMenuLink for direct navigation targets.

  • NavigationMenuLink accepts active when the current route should be visually highlighted.

  • Keep the content panel layout inside NavigationMenuContent simple and list-like so keyboard navigation stays predictable.

API Reference

PropType
delayOpen?number

Delay before opening on hover (ms)

Typenumber
delayClose?number

Delay before closing on mouse leave (ms)

Typenumber
openOnFocus?boolean

Whether focusing a trigger opens its content (default: false)

Typeboolean
side?Side

Preferred side of viewport relative to trigger

TypeSide
align?Align

Alignment of viewport relative to trigger

TypeAlign
sideOffset?number

Distance from trigger to viewport (px)

Typenumber
alignOffset?number

Offset along alignment axis (px)

Typenumber
positionMethod?PositionMethod

Positioning strategy for the shared viewport positioner

TypePositionMethod
safeTriangle?boolean

Enable hover safe-triangle behavior (opt-in)

Typeboolean
debugSafeTriangle?boolean

Debug hover safe-triangle polygon

Typeboolean
mountStrategy?MountStrategy

Detach inactive panels by default; eager keeps them connected and hidden. How to mount the navigation menu panels. Use eager for primary navigation to keep closed-panel links in the DOM after initialization. Both modes include all panel links in the server HTML. - eager: Keep closed panels connected and hidden. - lazy: Remove closed panels from the DOM until they are activated.

TypeMountStrategy
Default'eager'
PropType
side?Side

Preferred side of viewport relative to trigger

TypeSide
align?Align

Alignment of viewport relative to trigger

TypeAlign
sideOffset?number

Distance from trigger to viewport (px)

Typenumber
alignOffset?number

Offset along alignment axis (px)

Typenumber
PropType
side?Side

Preferred side of viewport relative to trigger

TypeSide
align?Align

Alignment of viewport relative to trigger

TypeAlign
sideOffset?number

Distance from trigger to viewport (px)

Typenumber
alignOffset?number

Offset along alignment axis (px)

Typenumber
valuestring

Value that identifies this menu item.

Typestring

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the navigation menu root. The root emits the outbound events.

Outbound events

Event Detail
navigation-menu:change { value: string | null }

Inbound events

Event Detail
navigation-menu:set { value: string | null }

Read the installed source for the complete prop types.

When to use Navigation Menu

Use Navigation Menu for the main sections of a site. Keep direct destinations as links and use triggers only when they open a group. Organize popup content so the first useful destination is easy to find.

Keyboard and behavior

The data-slot controller handles opening, timing, and pointer movement between parts. Test keyboard focus through links and triggers, including Escape from an open panel. Provide a separate narrow-screen composition when the desktop layout no longer fits.

Theme and layout

Delay, side, and alignment props tune the existing behavior. The safe-triangle option helps pointer travel but does not replace a clear layout. Check panels at viewport edges after changing widths.