Navigation Menu for Astro
Astro navigation groups with links and optional popup panels.
Installation
bunx --bun shadcn@latest add @gnostic/navigation-menunpx shadcn@latest add @gnostic/navigation-menupnpm dlx shadcn@latest add @gnostic/navigation-menuInstall component packages
bun add @data-slot/navigation-menunpm install @data-slot/navigation-menupnpm add @data-slot/navigation-menuCopy the files
src/components/ui/navigation-menu/index.tssrc/components/ui/navigation-menu/navigation-menu-content.astrosrc/components/ui/navigation-menu/navigation-menu-indicator.astrosrc/components/ui/navigation-menu/navigation-menu-item.astrosrc/components/ui/navigation-menu/navigation-menu-link.astrosrc/components/ui/navigation-menu/navigation-menu-list.astrosrc/components/ui/navigation-menu/navigation-menu-positioner.astrosrc/components/ui/navigation-menu/navigation-menu-trigger-style.tssrc/components/ui/navigation-menu/navigation-menu-trigger.astrosrc/components/ui/navigation-menu/navigation-menu.astrosrc/components/ui/navigation-menu/types.ts
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
NavigationMenuIndicatorinNavigationMenuList. Its position depends on measurements from that list. -
Use
NavigationMenuTriggerfor items that open richer panels andNavigationMenuLinkfor direct navigation targets. -
NavigationMenuLinkacceptsactivewhen the current route should be visually highlighted. -
Keep the content panel layout inside
NavigationMenuContentsimple and list-like so keyboard navigation stays predictable.
API Reference
NavigationMenuProps
delayOpen?number
Delay before opening on hover (ms)
numberdelayClose?number
Delay before closing on mouse leave (ms)
numberopenOnFocus?boolean
Whether focusing a trigger opens its content (default: false)
booleanside?Side
Preferred side of viewport relative to trigger
Sidealign?Align
Alignment of viewport relative to trigger
AlignsideOffset?number
Distance from trigger to viewport (px)
numberalignOffset?number
Offset along alignment axis (px)
numberpositionMethod?PositionMethod
Positioning strategy for the shared viewport positioner
PositionMethodsafeTriangle?boolean
Enable hover safe-triangle behavior (opt-in)
booleandebugSafeTriangle?boolean
Debug hover safe-triangle polygon
booleanmountStrategy?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.
MountStrategy'eager'NavigationMenuContentProps
side?Side
Preferred side of viewport relative to trigger
Sidealign?Align
Alignment of viewport relative to trigger
AlignsideOffset?number
Distance from trigger to viewport (px)
numberalignOffset?number
Offset along alignment axis (px)
numberNavigationMenuItemProps
side?Side
Preferred side of viewport relative to trigger
Sidealign?Align
Alignment of viewport relative to trigger
AlignsideOffset?number
Distance from trigger to viewport (px)
numberalignOffset?number
Offset along alignment axis (px)
numbervaluestring
Value that identifies this menu item.
stringSee 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.