Navigation Menu
SaveA top navigation bar with dropdown panels of links and descriptions, built on Base UI Navigation Menu, whose panel glides and resizes between triggers.
- Category
- Navigation
- Version
- 0.1.0
- Frameworks
- Next.js, Vite + React
- Styling
- Tailwind CSS v4
Preview
Navigation Menu preview
Northwind
Installation
npx @shakenui/cli add navigation-menuReview the plan first. A dry run lists every file and package without changing anything:
npx @shakenui/cli add navigation-menu --dry-runUsage
navigation-menu-example.tsx
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuPanelLink,
NavigationMenuTrigger,
} from "@/components/shaken/ui/navigation-menu";
const icon = { viewBox: "0 0 16 16", fill: "none" } as const;
const stroke = { stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" } as const;
const platform = [
{
title: "Agents",
description: "Run coding agents against your repositories.",
href: "#agents",
icon: (
<svg {...icon}>
<rect x="3" y="4.5" width="10" height="8" rx="2" {...stroke} />
<path d="M8 2.5v2M6 8.25v.5M10 8.25v.5" {...stroke} />
</svg>
),
},
{
title: "Approvals",
description: "Pause risky steps until a person signs off.",
href: "#approvals",
icon: (
<svg {...icon}>
<circle cx="8" cy="8" r="5.25" {...stroke} />
<path d="M6.6 6.1v3.8M9.4 6.1v3.8" {...stroke} />
</svg>
),
},
{
title: "Traces",
description: "Inspect every model call, tool call, and token.",
href: "#traces",
icon: (
<svg {...icon}>
<path d="M2.75 4h6.5M5 8h8.25M2.75 12h5" {...stroke} />
</svg>
),
},
{
title: "Evaluations",
description: "Score agent runs against your own test sets.",
href: "#evaluations",
icon: (
<svg {...icon}>
<path d="M2.75 13.25h10.5M4.5 10.5V8M8 10.5V4.5M11.5 10.5V6.5" {...stroke} />
</svg>
),
},
];
const developers = [
{ title: "Quickstart", description: "Ship a first agent in ten minutes.", href: "#quickstart" },
{ title: "API reference", description: "Endpoints, events, and error codes.", href: "#api" },
{ title: "CLI", description: "Start and stream runs from a terminal.", href: "#cli" },
{ title: "Changelog", description: "What changed in each release.", href: "#changelog" },
];
export default function NavigationMenuExample() {
return (
<div className="flex w-full max-w-3xl items-center gap-4 rounded-xl border border-zinc-950/10 bg-white px-3 py-2 dark:border-white/10 dark:bg-black">
<span className="hidden pl-1 text-sm font-semibold text-zinc-950 sm:inline dark:text-white">Northwind</span>
<NavigationMenu aria-label="Main">
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Platform</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="m-0 grid list-none gap-0.5 p-0 sm:w-[34rem] sm:grid-cols-2">
{platform.map((link) => (
<li key={link.href}>
<NavigationMenuPanelLink href={link.href} title={link.title} description={link.description} icon={link.icon} />
</li>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>Developers</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className="m-0 grid list-none gap-0.5 p-0 sm:w-80">
{developers.map((link) => (
<li key={link.href}>
<NavigationMenuPanelLink href={link.href} title={link.title} description={link.description} />
</li>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuLink href="#pricing">Pricing</NavigationMenuLink>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
</div>
);
}API
| Prop | Type | Default | Description |
|---|---|---|---|
| NavigationMenu value / defaultValue / onValueChange | any / any / (value, details) => void | — | The open item's value; null when closed. Leave unset for an uncontrolled menu. |
| NavigationMenu delay / closeDelay | number | 50 / 50 | Hover delays in ms before opening and closing. |
| NavigationMenu align / sideOffset | "start" | "center" | "end" / number | "start" / 8 | Panel alignment against the open trigger, and its gap below the triggers in pixels. |
| NavigationMenu popupClassName | string | — | Classes for the floating panel, for example a different radius. |
| NavigationMenuTrigger | Base UI NavigationMenu.Trigger props | — | Opens its item's panel on hover or click. Sets data-popup-open while open; the chevron turns. |
| NavigationMenuContent | Base UI NavigationMenu.Content props | — | Panel content for a trigger. Set the width of your grid inside it (for example sm:w-[34rem]). |
| NavigationMenuLink active | boolean | false | A top-level link with no panel. active sets aria-current="page". |
| NavigationMenuPanelLink title / description / icon | ReactNode | — | A link inside a panel with a title, a one-line description, and an optional icon tile. Closes the panel when followed. |
| render | ReactElement | — | On links, your router's link component, for example render={<Link href="/docs" />}. |
Accessibility
- Renders a nav landmark; name it with aria-label ("Main" in the example).
- Triggers are buttons with aria-expanded. Left and Right arrows move between top-level entries; Enter, Space, or ArrowDown opens a panel while focus stays on the trigger, and Tab then moves into the panel's links in order.
- Escape closes the panel and returns focus to its trigger; moving focus out of the menu also closes it.
- The current page link has aria-current="page" via the active prop.
- Panel links show a tint and an inset sky focus ring on keyboard focus.
- The panel grows from the open trigger in 260ms, then glides, resizes, and slides content toward the side the pointer moved to; it fades out in 110ms. With reduced motion the size and position change instantly and content only cross-fades without moving.
Files
Installed into src/components/shaken, or components/shaken when the project has no src directory.
src/components/shaken/ui/navigation-menu.tsxnavigation-menu- npm packages: @base-ui/react@^1.9.0React and Tailwind CSS v4 required
Source
The exact source the CLI installs, from /r/items/react/navigation-menu/0.1.0.json.
ui/navigation-menu.tsxShowHide
ui/navigation-menu.tsx
"use client";
import { NavigationMenu as BaseNavigationMenu } from "@base-ui/react/navigation-menu";
import type { ReactNode } from "react";
type ClassName<State> = string | ((state: State) => string | undefined) | undefined;
function cx(...classes: (string | false | null | undefined)[]) {
return classes.filter(Boolean).join(" ");
}
/** Prepends base classes while keeping Base UI's state-function form of className working. */
function withBase<State>(base: string, className: ClassName<State>) {
return typeof className === "function" ? (state: State) => cx(base, className(state)) : cx(base, className);
}
// One quint ease-out shared by the panel, its size, its position, and the sliding content.
const ease = "ease-[cubic-bezier(0.22,1,0.36,1)]";
type PositionerProps = BaseNavigationMenu.Positioner.Props;
export interface NavigationMenuProps extends BaseNavigationMenu.Root.Props {
/** Alignment of the dropdown panel against the open trigger. */
align?: PositionerProps["align"];
/** Gap between the triggers and the panel, in pixels. */
sideOffset?: PositionerProps["sideOffset"];
/** Classes for the floating panel. */
popupClassName?: string;
/** Element to portal the panel into. Defaults to `document.body`. */
container?: BaseNavigationMenu.Portal.Props["container"];
}
/**
* Site navigation with dropdown panels. Renders a `<nav>` with your `NavigationMenuList`, plus one
* shared floating panel: it grows from the open trigger, then glides and resizes between triggers
* while the content slides in from the side the pointer came from. All of it is removed with
* reduced motion.
*/
export function NavigationMenu({
align = "start",
sideOffset = 8,
popupClassName,
container,
className,
children,
...props
}: NavigationMenuProps) {
return (
<BaseNavigationMenu.Root className={withBase("relative min-w-0", className)} {...props}>
{children}
<BaseNavigationMenu.Portal container={container}>
<BaseNavigationMenu.Positioner
side="bottom"
align={align}
sideOffset={sideOffset}
collisionPadding={12}
collisionAvoidance={{ side: "none" }}
className={cx(
"z-50 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width)",
`transition-[top,left,right,bottom] duration-260 ${ease} motion-reduce:transition-none data-[instant]:transition-none`,
// A bridge across the gap, so moving the pointer from a trigger to the panel keeps it open.
"before:absolute before:inset-x-0 before:-top-2 before:h-2 before:content-['']",
)}
>
<BaseNavigationMenu.Popup
className={cx(
"relative h-(--popup-height) w-(--popup-width) origin-(--transform-origin) overflow-hidden rounded-xl outline-none",
"border border-zinc-950/10 bg-white text-zinc-950 shadow-[0_12px_32px_-8px_rgb(0_0_0/0.18)]",
"dark:border-white/15 dark:bg-black dark:text-white dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]",
// Size follows the active content; enter grows from the trigger, exit is a quicker fade.
`transition-[width,height,opacity,scale] duration-260 ${ease} motion-reduce:transition-none`,
"data-[starting-style]:opacity-0 motion-safe:data-[starting-style]:scale-96",
"data-[ending-style]:opacity-0 data-[ending-style]:duration-110 data-[ending-style]:ease-out motion-safe:data-[ending-style]:scale-98",
popupClassName,
)}
>
<BaseNavigationMenu.Viewport className="relative size-full overflow-hidden" />
</BaseNavigationMenu.Popup>
</BaseNavigationMenu.Positioner>
</BaseNavigationMenu.Portal>
</BaseNavigationMenu.Root>
);
}
/** The row of top-level entries. */
export function NavigationMenuList({ className, ...props }: BaseNavigationMenu.List.Props) {
return <BaseNavigationMenu.List className={withBase("m-0 flex list-none items-center gap-0.5 p-0", className)} {...props} />;
}
/** One top-level entry: a `NavigationMenuTrigger` with `NavigationMenuContent`, or a single `NavigationMenuLink`. */
export function NavigationMenuItem(props: BaseNavigationMenu.Item.Props) {
return <BaseNavigationMenu.Item {...props} />;
}
const topLevel = cx(
"group inline-flex h-8 items-center gap-1 rounded-lg px-3 text-sm font-medium whitespace-nowrap no-underline select-none",
"text-zinc-600 dark:text-zinc-400",
"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none",
"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white",
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500",
);
/**
* Opens its panel on hover and on click; Enter, Space, and ArrowDown open it from the keyboard, and
* Tab moves on into the panel. The chevron turns while the panel is open.
*/
export function NavigationMenuTrigger({ className, children, ...props }: BaseNavigationMenu.Trigger.Props) {
return (
<BaseNavigationMenu.Trigger
className={withBase(
cx(
topLevel,
"pr-2",
"data-[popup-open]:bg-zinc-950/[0.04] data-[popup-open]:text-zinc-950 dark:data-[popup-open]:bg-white/[0.06] dark:data-[popup-open]:text-white",
),
className,
)}
{...props}
>
{children}
<BaseNavigationMenu.Icon
className={cx(
"inline-flex text-zinc-400 dark:text-zinc-500",
`transition-[rotate,color] duration-200 ${ease} motion-reduce:transition-none`,
"group-hover:text-zinc-600 data-[popup-open]:rotate-180 data-[popup-open]:text-zinc-600 dark:group-hover:text-zinc-300 dark:data-[popup-open]:text-zinc-300",
)}
>
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" className="size-3.5">
<path d="m4.5 6.25 3.5 3.5 3.5-3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</BaseNavigationMenu.Icon>
</BaseNavigationMenu.Trigger>
);
}
/**
* The panel content for a trigger. It slides a short distance in from the side of the trigger the
* pointer moved toward while the previous content slides out the other way.
*/
export function NavigationMenuContent({ className, ...props }: BaseNavigationMenu.Content.Props) {
return (
<BaseNavigationMenu.Content
className={withBase(
cx(
"h-full w-[calc(100vw-1.5rem)] p-2 sm:w-max",
`transition-[opacity,translate] duration-260 ${ease} motion-reduce:transition-none`,
"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-160",
"motion-safe:data-[starting-style]:data-[activation-direction=right]:translate-x-12",
"motion-safe:data-[starting-style]:data-[activation-direction=left]:-translate-x-12",
"motion-safe:data-[ending-style]:data-[activation-direction=right]:-translate-x-12",
"motion-safe:data-[ending-style]:data-[activation-direction=left]:translate-x-12",
),
className,
)}
{...props}
/>
);
}
export interface NavigationMenuLinkProps extends BaseNavigationMenu.Link.Props {}
/**
* A top-level link with no panel. Pass `active` for the current section, which sets
* `aria-current="page"`, and `render={<Link href="…" />}` for your router.
*/
export function NavigationMenuLink({ className, ...props }: NavigationMenuLinkProps) {
return (
<BaseNavigationMenu.Link
className={withBase(cx(topLevel, "data-[active]:text-zinc-950 dark:data-[active]:text-white"), className)}
{...props}
/>
);
}
export interface NavigationMenuPanelLinkProps extends Omit<BaseNavigationMenu.Link.Props, "title"> {
/** The link's name. */
title: ReactNode;
/** One line about where the link goes, in the secondary text color. */
description?: ReactNode;
/** A 16px icon shown in a hairline tile before the text. */
icon?: ReactNode;
}
/**
* A link inside a panel with a title, an optional description, and an optional icon tile. Closes
* the panel when followed. Hover and keyboard highlight only change the background tint.
*/
export function NavigationMenuPanelLink({ title, description, icon, className, closeOnClick = true, ...props }: NavigationMenuPanelLinkProps) {
return (
<BaseNavigationMenu.Link
closeOnClick={closeOnClick}
className={withBase(
cx(
"group/link flex items-start gap-3 rounded-lg p-2.5 text-left no-underline outline-none",
"transition-[background-color] duration-150 ease-out motion-reduce:transition-none",
"hover:bg-zinc-950/[0.04] focus-visible:bg-zinc-950/[0.04] dark:hover:bg-white/[0.06] dark:focus-visible:bg-white/[0.06]",
"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500",
"data-[active]:bg-zinc-950/[0.06] dark:data-[active]:bg-white/[0.09]",
),
className,
)}
{...props}
>
{icon ? (
<span
aria-hidden="true"
className={cx(
"flex size-8 shrink-0 items-center justify-center rounded-lg border text-zinc-600 [&_svg]:size-4",
"border-zinc-950/10 shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:border-white/15 dark:text-zinc-300 dark:shadow-none",
"transition-[color,border-color] duration-150 ease-out motion-reduce:transition-none",
"group-hover/link:border-zinc-950/20 group-hover/link:text-zinc-950 dark:group-hover/link:border-white/25 dark:group-hover/link:text-white",
)}
>
{icon}
</span>
) : null}
<span className="flex min-w-0 flex-col gap-0.5">
<span className="text-sm leading-5 font-medium text-zinc-950 dark:text-white">{title}</span>
{description ? <span className="text-[13px] leading-5 text-zinc-500 dark:text-zinc-400">{description}</span> : null}
</span>
</BaseNavigationMenu.Link>
);
}