Skip to content

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.

src/registry/blocks/floating-nav.tsx/r/floating-nav.json

Installation

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

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/floating-nav.json

Usage

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

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

API reference

FloatingNav props
PropTypeDefault
brandLogo or wordmark at the left. Defaults to the Lumen wordmark.React.ReactNode( <span className="flex items-center ...
brandHrefWhere the brand links to.string"/"
ctaSolid button at the right. Renders as a link when `href` is set.{ label: string; href?: string; onClick?: () => void }{ label: "Start free" }
secondaryGhost link before the CTA, hidden on the smallest screens. Pass null to remove it.{ label: string; href?: string } | null{ label: "Sign in", href: "#" }
classNamestring-

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.

Keyboard interactions

Keyboard interactions
KeyAction
TabMoves through the brand, the links and the buttons. On desktop the hover highlight follows focus.
EnterorSpaceOn the menu button (below md), opens or closes the link panel.
EscapeCloses 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.

Frequently asked questions

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.

Dependencies

npm

lucide-reactmotion

Built from

All navigation components

Learn more