Floating Nav

A top bar that shrinks into a floating pill and slips away while you read down.

no dependenciesMIT · free

Scroll inside this box ↓

The bar becomes a floating pill, hides while you scroll down, and comes back when you scroll up.

Installation

npx shadcn@latest add https://ombakui.com/r/floating-nav.json

Usage

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

// at the top of your layout
<FloatingNav>
  <Logo />
  <nav>…links…</nav>
</FloatingNav>

Props

PropTypeDefaultDescription
children*ReactNode–Nav content: logo, links, a button…
thresholdnumber40Pixels scrolled before the bar turns into a floating pill.
hideOnScrollbooleantrueHide when scrolling down, show again when scrolling up.
scrollContainerReact.RefObject<HTMLElement | null>–Use a scrollable element instead of the window, e.g. for demos.
classNamestring–