NavigationMenu
NavigationA site's or app's main navigation: <NavigationMenu.Root> holds a NavigationMenu.List of NavigationMenu.Items. An item is a NavigationMenu.Link (style it with navigationMenuTriggerStyle() at the top level; active marks the current page) or a NavigationMenu.Trigger with a NavigationMenu.Content panel of links. Panels open on hover or click, in a shared viewport below the bar (viewport={false} places each under its trigger). Arrow keys move along the bar, Escape closes a panel.
import { NavigationMenu } from '@limerdev/zest'; DropdownMenu or Menubar. Many sections in an admin app: a sidebar of links.Examples
Basic
Triggers open panels of links in a shared box below the bar; a top-level link uses navigationMenuTriggerStyle(). active marks the current page.
<script lang="ts">
import { NavigationMenu, navigationMenuTriggerStyle } from '@limerdev/zest';
type Page = { href: string; title: string; description: string };
const reports: Page[] = [
{ href: '#hours', title: 'Hours', description: 'Logged and billable hours per week.' },
{ href: '#invoices', title: 'Invoices', description: 'Sent, paid and overdue.' },
{ href: '#budgets', title: 'Budgets', description: 'Hours used against each budget.' }
];
</script>
<div class="flex h-64 items-start justify-center">
<NavigationMenu.Root aria-label="Main">
<NavigationMenu.List>
<NavigationMenu.Item>
<NavigationMenu.Trigger>Reports</NavigationMenu.Trigger>
<NavigationMenu.Content>
<ul class="grid w-80 gap-1">
{#each reports as report (report.href)}
<li>
<NavigationMenu.Link href={report.href}>
<span class="font-medium">{report.title}</span>
<span class="text-muted">{report.description}</span>
</NavigationMenu.Link>
</li>
{/each}
</ul>
</NavigationMenu.Content>
</NavigationMenu.Item>
<NavigationMenu.Item>
<NavigationMenu.Link href="#projects" active class={navigationMenuTriggerStyle()}>
Projects
</NavigationMenu.Link>
</NavigationMenu.Item>
<NavigationMenu.Item>
<NavigationMenu.Link href="#settings" class={navigationMenuTriggerStyle()}>
Settings
</NavigationMenu.Link>
</NavigationMenu.Item>
</NavigationMenu.List>
</NavigationMenu.Root>
</div> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
NavigationMenu.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| delayDuration | number | 200 | The amount of time in ms from when the mouse enters a trigger until the content opens. |
| dir | "ltr" | "rtl" | "ltr" | The reading direction of the content. |
| onValueChange | OnChangeFn<string> | – | The callback to call when a menu item is selected. |
| orientation | "horizontal" | "vertical" | – | The orientation of the menu. |
| skipDelayDuration | number | 300 | The amount of time in ms that a user has to enter another trigger without incurring a delay again. |
| value bindable | string | '' | The value of the currently open menu item. |
| viewport | boolean | true | Open every panel in one shared box below the bar; false opens each under its trigger. |
NavigationMenu.List
No props of its own beyond the common ones.
NavigationMenu.Item
| Prop | Type | Default | Description |
|---|---|---|---|
| openOnHover | boolean | true | Whether to open the menu associated with the item when the item's trigger is hovered. |
| value | string | – | The value of the menu item. |
NavigationMenu.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | null | false | true | false | Whether the trigger is disabled. |
NavigationMenu.Content
| Prop | Type | Default | Description |
|---|---|---|---|
| escapeKeydownBehavior | "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" | – | Behavior when the escape key is pressed while the menu content is open. |
| forceMount | boolean | false | Whether to forcefully mount the content, regardless of the open state. This is useful when wanting to use more custom transition and animation libraries. |
| interactOutsideBehavior | "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" | – | Behavior when an interaction occurs outside the content. |
| onEscapeKeydown | ((event: KeyboardEvent) => void) | – | Callback fires when an escape keydown event occurs. Default behavior can be prevented with event.preventDefault() |
| onFocusOutside | ((event: FocusEvent) => void) | – | Callback fired when a focus event occurs outside the content. Default behavior can be prevented with event.preventDefault() |
| onInteractOutside | ((event: PointerEvent) => void) | – | Callback fired when an interaction occurs outside the content. Default behavior can be prevented with event.preventDefault() |
NavigationMenu.Link
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | – | Whether the link is the current active page |
| onSelect | ((e: Event) => void) | – | A callback fired when the link is clicked. Default behavior can be prevented with event.preventDefault() |
NavigationMenu.Viewport
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | false | Whether to forcefully mount the content, regardless of the open state. This is useful when wanting to use more custom transition and animation libraries. |
NavigationMenu.Indicator
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | false | Whether to forcefully mount the content, regardless of the open state. This is useful when wanting to use more custom transition and animation libraries. |
NavigationMenu.Sub
| Prop | Type | Default | Description |
|---|---|---|---|
| onValueChange | OnChangeFn<string> | – | A callback fired when the active menu item changes. |
| orientation | "horizontal" | "vertical" | – | The orientation of the menu. |
| value bindable | string | – | The value of the currently open menu item within the menu. |