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.
Installation
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
import { FloatingNav } from "@/components/ui/floating-nav"
export function Example() {
return (
<FloatingNav />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| brandLogo or wordmark at the left. Defaults to the Lumen wordmark. | React.ReactNode | ( <span className="flex items-center ... |
| brandHrefWhere the brand links to. | string | "/" |
| linksPrimary navigation links. | NavLink[] | LINKS |
| 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: "#" } |
| className | string | - |
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
| Key | Action |
|---|---|
| Tab | Moves through the brand, the links and the buttons. On desktop the hover highlight follows focus. |
| EnterorSpace | 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 witharia-controls. - The menu button's label switches between "Open menu" and "Close menu", with
aria-expandedto 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
Built from