Navigation Menu
The marker stretches between items and the panel resizes on a spring to fit each menu.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/navigation-menuThis adds components/keyframery/navigation-menu.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
NavigationMenuViewport,
} from "@/components/keyframery/navigation-menu"
export default function Usage() {
return (
<NavigationMenu aria-label="Main">
<NavigationMenuList>
<NavigationMenuItem value="products">
<NavigationMenuTrigger>Products</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink href="/analytics">Analytics</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
</NavigationMenuList>
<NavigationMenuViewport />
</NavigationMenu>
)
}Anatomy
How the parts fit together:
NavigationMenu
├── NavigationMenuList
│ └── NavigationMenuItem
│ ├── NavigationMenuTrigger
│ └── NavigationMenuContent
│ └── NavigationMenuLink
└── NavigationMenuViewportExamples
Site navigation
Panels open on hover or click. Moving to the next trigger slides the panel across, and the viewport resizes to fit.
Motion
| Move | What you see |
|---|---|
| Stretch | The marker stretches from one item to the next. |
| Spring | The panel resizes on a spring to fit each menu. |
| Direction | Content slides in from the side you moved toward, and links arrive in a cascade. |
Timing and springiness follow the motion style you set. To change how fast this navigation menu moves, pass speed:
<NavigationMenu speed="fast">
…
</NavigationMenu>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--navigation-menu-surface | Viewport surface | --popover |
--navigation-menu-ink | Panel link text | --foreground; --popover-foreground for viewport |
--navigation-menu-muted | Trigger and icon text | --muted-foreground |
--navigation-menu-highlight | Indicator and highlighted links | --accent |
--navigation-menu-radius | Viewport corners | 14px |
--navigation-menu-item-radius | Trigger and indicator corners | 9px |
--navigation-menu-height | Top-level item height | 2rem |
--navigation-menu-gap | Top-level item gap | 0.125rem |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK navigation menu reference.
NavigationMenu
Renders a <element>, and takes its props too.
Prop
Type
NavigationMenuItem
Renders a <li>, and takes its props too.
Prop
Type
NavigationMenuTrigger
Renders a <button>, and takes its props too.
Prop
Type
NavigationMenuContent
Renders a <div>, and takes its props too.
Prop
Type
NavigationMenuLink
Renders a <a>, and takes its props too.
Prop
Type
NavigationMenuViewport
Renders a <div>, and takes its props too.
Prop
Type
NavigationMenuLinkIcon
Renders a <span>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
NavigationMenuList: a<ul>NavigationMenuIndicator: a<div>
Keyboard
| Key | What it does |
|---|---|
| Enter | Opens the focused trigger's panel. |
| ← → | Moves between triggers. |
| ↓ | Moves into the open panel. |
| Tab | Moves through the panel's links. |
| Escape | Closes the panel. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's navigation menu with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/navigation-menu"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/navigation-menu"Questions
How does the animated Navigation Menu for UI SDK move?
Stretch: The marker stretches from one item to the next. Spring: The panel resizes on a spring to fit each menu. Direction: Content slides in from the side you moved toward, and links arrive in a cascade.
Do I need Motion or Framer Motion for the animated Navigation Menu?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/navigation-menu instead. It has the same parts and props as @ui-sdk/react/navigation-menu and adds motion only.
What happens to the Navigation Menu when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.