Skip to Content
zjkm-ui
Components

Auto-hide Navbar

A navbar that hides as you scroll down and returns as you scroll up.

Scroll this page down and back up to see the bar hide and return.

Props
<AutoHideNavbar>
  <MyNav />
</AutoHideNavbar>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/auto-hide-navbar.json
import { AutoHideNavbar } from "@/components/auto-hide-navbar"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

Wrap your navbar and it slides away as you scroll down, then comes back as soon as you scroll up, giving content the room. It never hides while something inside it has keyboard focus.

import { AutoHideNavbar } from "@/components/auto-hide-navbar";

export function SiteHeader() {
  return (
    <AutoHideNavbar>
      <MyNav />
    </AutoHideNavbar>
  );
}

Props

PropTypeDefaultDescription
childrenReactNodeYour navbar's content.
thresholdnumber64Pixels scrolled before it may hide.
classNamestringClasses for the root element.

With reduced motion, it hides and returns without sliding.

On this page