Mega Menu
A large dropdown navigation menu whose panel height morphs smoothly to fit as you switch items, with hover and keyboard support.
This is a WebberUI Pro component
Free during the launch campaign: sign up or sign in, then hit “Copy install command” in the preview above and it installs straight away — no payment, no credit card. The command below returns 401 while you are signed out.
npx shadcn@latest add "https://webberui.com/r/mega-menu.json?t=<install token>"Playground
Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.
<MegaMenu />
Installation
npx shadcn@latest add "https://webberui.com/r/mega-menu.json?t=<install token>"Or, once registries are configured in components.json, install it as @webberui/mega-menu.
Usage
Assemble it from compound components. Every MegaMenuItem needs a unique value and contains one MegaMenuTrigger and one MegaMenuContent.
import {
MegaMenu,
MegaMenuList,
MegaMenuItem,
MegaMenuTrigger,
MegaMenuContent,
} from "@/components/ui/mega-menu";
<MegaMenu align="center">
<MegaMenuList label="Main navigation">
<MegaMenuItem value="products">
<MegaMenuTrigger>Products</MegaMenuTrigger>
<MegaMenuContent>{/* Large panel content */}</MegaMenuContent>
</MegaMenuItem>
<MegaMenuItem value="resources">
<MegaMenuTrigger>Resources</MegaMenuTrigger>
<MegaMenuContent>{/* Another set of content, possibly a different height */}</MegaMenuContent>
</MegaMenuItem>
</MegaMenuList>
</MegaMenu>When panels for different items have different sizes, the container morphs its height and width automatically as you switch, instead of jumping instantly.
controlled mode
Pass value (the expanded item's value, or null for collapsed) and onValueChange to take over the open state; when omitted, the component manages it internally.
const [open, setOpen] = useState<string | null>(null);
<MegaMenu value={open} onValueChange={setOpen}>
{/* ... */}
</MegaMenu>Props
MegaMenu
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | null | — | The expanded item in controlled mode; null means collapsed |
defaultValue | string | null | null | Initially expanded item in uncontrolled mode |
onValueChange | (value: string | null) => void | — | Callback fired when the expanded item changes |
align | "start" | "center" | "end" | "start" | Horizontal alignment of the panel relative to the navigation bar |
closeDelay | number | 150 | Milliseconds to wait before closing after the mouse leaves |
MegaMenuList
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | "Main navigation" | Accessible name for the navigation bar (nav) |
className | string | — | Appended to the navigation bar container's className |
MegaMenuItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Unique identifier for this item (required) |
className | string | — | Appended to the item container's (li) className |
MegaMenuTrigger / MegaMenuContent
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Trigger content / panel content |
className | string | — | Appended className (for Content it applies to the content area) |
How it works
- A single morphing container: each
MegaMenuContentregisters its content into a shared collection at render time, and an internal Viewport renders them all in one container carryinglayout; when you switch items,popLayouttakes the exiting panel out of the layout flow so the container immediately measures the new content and tweens its height. - Hover intent: moving the mouse onto a trigger expands it, and leaving the navigation bar only closes it after
closeDelay, which leaves a buffer for moving onto the panel; moving back in cancels the close. - The panel sits right under the navigation bar: it is an absolutely positioned child inside the
navrather than a portal, so moving the mouse between the trigger and the panel never closes it by accident.
Accessibility
- The trigger is a native
buttoncarryingaria-haspopup,aria-expanded, and — while expanded —aria-controlspointing at the panel region (role="region"). - Keyboard operation:
Enter/Spacetoggles expansion;ArrowLeft/ArrowRightplusHome/Endmove between triggers (switching the panel too when one is already open);ArrowDownexpands and moves focus into the panel;Escapecloses it and focus returns to the trigger. - Clicking outside the navigation bar closes the panel.
- When the user has "reduce motion" enabled at the system level, the height morph along with the displacement and scaling are disabled, leaving only a brief fade in and out.
Scroll-aware Navbar
A navigation bar that condenses, hides, or widens as you scroll — three variants sharing one consistent rhythm, with nested scroll container support.
Fullscreen Menu
A Nike-style fullscreen overlay menu — the backdrop unveils from the top down and the menu items slide up from under a mask in a staggered cascade.