# Morphing nav

> One dropdown that follows you along the menu, gliding and resizing to each item’s content.

Separate dropdowns that blink open and shut make a menu feel like a stack of boxes. Here there is one panel. Point at an item and it drops in underneath, sized to that item’s content; move to the next and the same panel glides across and resizes while the new content slides in from the side you moved toward. A soft highlight slides along under the items as you go. It works fully from the keyboard and closes when you leave.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/morphing-nav.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/morphing-nav
- Registry item (source): https://hairlineui.com/r/morphing-nav.json

## Usage

```tsx
import { MorphingNav } from "@/components/morphing-nav";

<MorphingNav
  items={[
    { id: "product", label: "Product", content: <ProductMenu /> },
    { id: "pricing", label: "Pricing", href: "/pricing" },
  ]}
/>
```

## In a site header

Give each panel its own width; the nav does the measuring, placing and morphing.

```tsx
import { MorphingNav } from "@/components/morphing-nav";

function ProductMenu() {
  return (
    <div className="grid w-[480px] grid-cols-2 gap-1 p-2">
      <a href="/workflows" className="rounded-xl p-3 hover:bg-accent">
        <span className="block text-sm font-medium">Workflows</span>
        <span className="text-xs text-muted-foreground">Chain steps that run on their own.</span>
      </a>
      {/* …more links */}
    </div>
  );
}

export function SiteHeader() {
  return (
    <header className="flex items-center justify-between border-b px-6 py-3">
      <Logo />
      <MorphingNav
        items={[
          { id: "product", label: "Product", content: <ProductMenu /> },
          { id: "solutions", label: "Solutions", content: <SolutionsMenu /> },
          { id: "pricing", label: "Pricing", href: "/pricing" },
        ]}
      />
      <a href="/signup">Start free</a>
    </header>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ id; label; href?; content? }[]` | – | Items with content open the panel; items with only an href are links. |
| `collisionPadding` | `number` | `16` | Space kept from the screen edges when placing the panel. |

## States

- **hover**: A soft highlight slides and resizes under the item you point at or focus.
- **open**: The panel drops in under the item, sized to its content and kept inside the screen.
- **move**: The panel glides and resizes (380ms) to the next item’s content; old content slides out one way, new content in from the other.
- **close**: Leaving the menu, Escape or a click elsewhere fades the panel away; Escape returns focus to the item.

## What it handles

Separate dropdowns that blink open and shut make a menu feel like a stack of boxes. Here one panel follows you along the menu and resizes to each item.

- **One panel for every item**: Point at an item and the panel drops in, sized to that item’s content. Give each panel its own width.
- **Content slides from where you came**: Moving to the next item glides and resizes the same panel, with the new content arriving from the side you moved toward.
- **A highlight that follows**: A soft highlight slides under the item you point at or focus.
- **Time to cross the gap**: With a mouse, a short delay lets you reach the panel. On touch, items open and close with a tap.
- **It stays on screen**: The panel keeps a margin from the screen edges and shifts to stay inside them.
- **Links stay links**: Items with only an href are links. Arrow keys move along the bar, and Escape closes the panel and returns focus.

## Replaces

a mega menu, dropdown positioning, hover intent delays, a sliding highlight, menu keyboard handling

## Where it fits

- **Product and solutions menus**: A site header where Product, Solutions and Resources each open a panel.
- **Documentation headers**: Group guides, references and examples under a few top-level items.
- **Marketplace categories**: Let people jump into a category from the header.
- **App top bars**: Grouped destinations in a product, with links and short descriptions.

## Notes

- A labelled navigation landmark. Items that open a panel are buttons with aria-expanded and aria-controls; links stay links.
- Left and Right move between items, Enter, Space or Down opens one and moves focus into it, and Escape closes it and returns focus.
- On touch screens, items open and close with a tap; with a mouse, a short delay lets you cross the gap to the panel.
- With reduced motion the panel switches content in place without gliding.

License: MIT (https://hairlineui.com/license#components)
