Base JS behaviour

Mobile menu

The same mega-menu items as a two-level drill-down for the mobile drawer; a direction-aware springy slide, managed focus (returning to the opener) and an inert hidden panel.

Real scenarios

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

The bookshop’s navigation drawer

The canonical host: a drawer from the inline-start carrying the same items the mega menu shows on desktop. Open “Shop” — the rows rise one after another and the panel glides with a spring; in Persian the slide flips by itself, because the track reads the direction. “Track my order” is the current page (aria-current), and with navigate every link swaps the page through wire:navigate — no reload.

Keyboard too: Enter drills in, focus lands on “Back”, and going back returns it to the very item you came from — the hidden panel is inert, so Tab never wanders into it.

Lalezar Bookshop

The account menu, in a narrow frame

The drill-down does not need a drawer: here it stands alone in a phone-width column. Each child carries its own icon, and the default slot pins whatever you hand it to the end of the root list — here a divider and the sign-out button, which answers with a toast.

The header does exactly this pairing for you: one $nav feeds the desktop mega menu, and below 56rem the burger serves the same items through this drill-down.

Important props

Important props
Prop Type Default What it does
items array [] The mega-menu structure: ['label' => …, 'href' => …, 'children' => […]; an item with children becomes a drill button, the rest are links — a current key marks the page you are on (aria-current). Children may carry an icon.
navigate bool false Puts wire:navigate on every link so the page swaps through Livewire without a reload — the same flag you hand to the header.
slot any — The default slot lands whatever you hand it at the end of the root list — dividers and sign-out/sign-in buttons; the header fills this same slot from mobileActions.

Snippet

{{-- کشوی موبایل: دریل‌داون + کنش‌های سنجاق‌شده در اسلات --}}
<x-nx::drawer side="start" wire:model="state.menuOpen" :title="config('app.name')">
    <x-nx::mobile-menu :items="$nav" navigate>
        <x-nx::divider style="margin-block: 0">یا</x-nx::divider>
        <x-nx::button variant="ghost" icon="x" block wire:click="logout">خروج از حساب</x-nx::button>
    </x-nx::mobile-menu>
</x-nx::drawer>

{{-- یا خود هدر: زیر ۵۶rem همبرگر همین را در کشوی خودش می‌آورد --}}
<x-nx::header :items="$nav" navigate>
    <x-slot:actions><x-nx::theme-toggle /></x-slot:actions>
</x-nx::header>