Keyframery

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.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/navigation-menu

This 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
└── NavigationMenuViewport

Examples

Panels open on hover or click. Moving to the next trigger slides the panel across, and the viewport resizes to fit.

Motion

MoveWhat you see
StretchThe marker stretches from one item to the next.
SpringThe panel resizes on a spring to fit each menu.
DirectionContent 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.

VariableWhat it changesDefault
--navigation-menu-surfaceViewport surface--popover
--navigation-menu-inkPanel link text--foreground; --popover-foreground for viewport
--navigation-menu-mutedTrigger and icon text--muted-foreground
--navigation-menu-highlightIndicator and highlighted links--accent
--navigation-menu-radiusViewport corners14px
--navigation-menu-item-radiusTrigger and indicator corners9px
--navigation-menu-heightTop-level item height2rem
--navigation-menu-gapTop-level item gap0.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.

Renders a <element>, and takes its props too.

Prop

Type

Renders a <li>, and takes its props too.

Prop

Type

Renders a <button>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <a>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

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

KeyWhat it does
EnterOpens the focused trigger's panel.
← →Moves between triggers.
↓Moves into the open panel.
TabMoves through the panel's links.
EscapeCloses 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.

All components

On this page