Base JS behaviour

Header

The site header with brand, mega menu, actions slot and floating / hide-on-scroll modes.

Real scenarios

The component as it is used in a product — not a specimen grid.

The shop-builder’s site header

Brand with its icon, a Features mega menu where every item carries its own description, a plain link marked aria-current, and the actions at the header’s end. “Log in” carries data-desktop: below 56rem it disappears and the burger takes over — the same items as a drill-down drawer, with the build-shop button arriving through the mobile-actions slot. The primary button answers a click with a toast and a spinner (wire:loading).

Narrow the window under 56rem: the nav and “Log in” fold away, the burger stays — and picking anything in the drawer does not close it, exactly like the panel it came from.

The landing page’s floating pill

Without items the header lays out just the brand and the actions, as a floating pill. Scroll down the hero: from the first few pixels the pill tightens — thinner, bordered, glassed and narrower (data-scrolled) — and loosens again when you come back up. The trial button toasts through wire:loading, so it stays honest while it “creates” the workspace.

Nabu
Log in

Open your storefront tonight

From 190,000 tomans a month, 14 days free — cancel from the panel, no phone calls.

  • Persian-first templates Right-to-left from the first pixel, not bolted on later.
  • Live sales analytics Today’s orders and best sellers while they happen.
  • Secure by default SSL, regional gateways and 99.9% uptime.

The reading header steps aside

hide-on-scroll is on: scrolling down the article, the header slips out of the way quietly; the first motion back up brings it back at once. While something inside it holds focus it refuses to hide, and the article’s link is copied by the button beside the title — never hostage to an open header.

The Nabu Notebook · 3 min read · 2025

Why the reading header must learn to leave

Reading a Persian article under an always-visible sticky header is like reading a book whose publisher thought the cover should stay open over the text. What the reader wants is plain: the most pixels for the words, and a quick way back to the navigation only when it is needed.

The hide-on-scroll pattern is exactly that bargain. The header travels with the reader’s pace: while they head down the page — at the peak of focus — it slips away, and at the first motion back up — the moment they look for a way out — it returns instantly.

A header should be like a good waiter: present the moment you need it, invisible the moment you don’t.

So it never becomes twitchy, the decision carries a small tolerance: a pixel of jitter or a slow crawl does not move it. The verdict follows the clear direction of the scroll, not every wheel event.

Accessibility survives too: while anything inside the header holds focus, it refuses to hide, so a keyboard user never lands in a control they cannot see — and the share link never depends on the header being open; it sits by the title, one press away.

Try it: read a few paragraphs down until the header goes, then nudge the wheel up — it is already back.

Important props

Important props
Prop Type Default What it does
variant string bar bar (default) runs full width and turns glass after a few pixels of scroll; floating is a pill that tightens as you scroll — thinner, bordered, narrower.
hideOnScroll bool false Slips away while the reader scrolls down and returns on the first motion back up; while anything inside it holds focus it refuses to hide.
items array [] The mega-menu items in the mega-menu shape (label + children, or href and current). Without items the header lays out just brand and actions — no burger either. The mobile drawer’s dialog name is fixed, so keep one header-with-items per page.
navigate bool false Brand, mega-menu and drawer links route through wire:navigate.
brand / brandHref slot|string نام اپ / '/' The header’s leading brand — icon and word in the brand slot; without the slot the app name sits there, and brandHref (default /) is its link.
label string null The navigation’s accessible name; it reaches the mega menu’s aria-label.
actions / mobile-actions slot — The header’s closing actions; data-desktop makes one desktop-only (hidden under 56rem) and mobile-actions takes its place inside the mobile drawer.

Snippet

<x-nx::header :items="$nav" label="راهبری اصلی" navigate>
    <x-slot:brand>{{ \NabuXUI\NabuXUI::icon('zap') }} نابوشاپ</x-slot:brand>
    <x-slot:actions>
        <x-nx::theme-toggle />
        <x-nx::button size="sm" variant="ghost" href="/login" data-desktop wire:navigate>ورود</x-nx::button>
        <x-nx::button size="sm" variant="primary" wire:click="save">ساخت فروشگاه</x-nx::button>
    </x-slot:actions>
    <x-slot:mobile-actions>
        <x-nx::button size="sm" variant="primary" block wire:click="save">ساخت فروشگاه</x-nx::button>
    </x-slot:mobile-actions>
</x-nx::header>

{{-- صفحهٔ فرود: قرص شناور که با خواندن کنار می‌رود --}}
<x-nx::header variant="floating" hide-on-scroll brand-href="/">
    <x-slot:brand>نابو</x-slot:brand>
    <x-slot:actions><x-nx::theme-toggle /></x-slot:actions>
</x-nx::header>