# Floating Nav

> A sticky marketing navbar that tucks into a floating pill after you scroll, with a hover highlight that glides between links and an animated mobile menu.

- Kind: Block (Navigation)
- Docs: https://ui.minidev.pro/docs/floating-nav
- Source (registry JSON with the full file): https://ui.minidev.pro/r/floating-nav.json
- License: MIT. One file, yours to edit after install.

## When to use

Use at the top of a landing page, above HeroSpotlight. It tracks window scroll. Below md the links move into a menu sheet: the toggle has aria-expanded/aria-controls, Escape closes it and returns focus, and choosing a link closes it. For an app shell with a sidebar use Topbar or Sidebar; for in-page section tabs use Tabs.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/floating-nav
```

Writes `components/ui/floating-nav.tsx` plus the MiniDev files it is built from (button) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/floating-nav.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { FloatingNav } from "@/components/ui/floating-nav"
```

From the npm package:

```tsx
import { FloatingNav } from "minidev-ui-kit/blocks/floating-nav"
```

## Usage

```tsx
import { FloatingNav } from "@/components/ui/floating-nav"

export function Example() {
  return (
    <FloatingNav />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `brand` | `React.ReactNode` | `( <span className="flex items-center ...` | no | Logo or wordmark at the left. Defaults to the Lumen wordmark. |
| `brandHref` | `string` | `"/"` | no | Where the brand links to. |
| `links` | `NavLink[]` | `LINKS` | no | Primary navigation links. |
| `cta` | `{ label: string; href?: string; onClick?: () => void }` | `{ label: "Start free" }` | no | Solid button at the right. Renders as a link when `href` is set. |
| `secondary` | `{ label: string; href?: string } \| null` | `{ label: "Sign in", href: "#" }` | no | Ghost link before the CTA, hidden on the smallest screens. Pass null to remove it. |
| `className` | `string` | - | no |  |

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Moves through the brand, the links and the buttons. On desktop the hover highlight follows focus. |
| `Enter` or `Space` | On the menu button (below `md`), opens or closes the link panel. |
| `Escape` | Closes the open mobile panel and returns focus to the menu button. |

## Accessibility

- The bar is a `<nav aria-label="Main">`; the mobile panel is a second `<nav aria-label="Main menu">` whose id the toggle references with `aria-controls`.
- The menu button's label switches between "Open menu" and "Close menu", with `aria-expanded` to match.
- With reduced motion the pill and hover highlight change without a spring, and the mobile panel appears without the scale and slide.

## FAQ

### How do I change when the header tucks into the pill?

It tucks once the window has scrolled more than 40px; the number is in the `useMotionValueEvent` call. It reads window scroll only, so inside a scrolling `div` it never tucks.

### Why does the CTA do nothing?

The default `cta` is `{ label: "Start free" }` with no `href` or `onClick`. Pass `href` to render it as a link, or `onClick` for a button. Pass `secondary={null}` to remove the Sign in link.

### Is the mobile menu a dialog?

No. Below `md` it is a disclosure panel under the bar: it does not trap focus or lock page scroll. Escape closes it and returns focus to the menu button, and choosing a link closes it.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`
- Built from: [button](https://ui.minidev.pro/docs/button/md)

## Related

- [Hero Spotlight](https://ui.minidev.pro/docs/hero-spotlight/md): A launch hero with a pulsing eyebrow, blur-in headline with a cursor lit second line, two actions, a proof line and a product visual that tilts into place.
- [Topbar](https://ui.minidev.pro/docs/topbar/md): App top bar that is 56px tall with a title or custom left content and a right slot for actions, avatars or search. Sits above the main content in dashboards.
- [Sidebar](https://ui.minidev.pro/docs/sidebar/md): App sidebar shell with a collapsed icon-only width and SidebarNavItem buttons that show icons, truncated labels and an active state. Built with Tailwind.
- [Tabs](https://ui.minidev.pro/docs/tabs/md): Tabs on Base UI with a raised thumb or a line underline that springs to the active tab, optional count badges, vertical orientation and roving keyboard focus.
- [Search Results Page](https://ui.minidev.pro/docs/search-results-page/md): A search results panel with a query input, result count and a list of hits, each showing a monospace item name, a tier badge and a one line summary.
- [Back Link](https://ui.minidev.pro/docs/back-link/md): Small back navigation link with a left arrow icon, muted text that darkens on hover and a visible focus ring. Defaults to the label Back and accepts any href.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
