Menubar

Navigation

A bar of menus, as in a desktop application: <Menubar.Root> holds a Menubar.Menu per menu, each with a Menubar.Trigger and a Menubar.Content. The contents take the same items as DropdownMenu: Item (variant="error", Shortcut), CheckboxItem, RadioGroup with RadioItems, Group with GroupHeading, Label, Separator and submenus. Left and Right move between menus, Down opens one, Escape closes.

import { Menubar } from '@limerdev/zest';
Menubar for AI tools (llms.txt)
Use for
A dense editor or tool with many commands grouped into a few menus (File, Edit, View).
Don't
Site navigation: use links or NavigationMenu. A single menu: use DropdownMenu.

Examples

Basic

A report editor's commands. Left and Right move between menus.

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).

Menubar.Root

Prop Type Default Description
dir "ltr" | "rtl" – The reading direction of the menubar.
loop boolean – When true, the roving focus will loop back to the first menu item when the last menu item is reached and vice verse.
onValueChange OnChangeFn<string> – A callback that is called when the active menu changes.
value bindable string '' The 'value' assigned to the currently active menu in the menubar.

Menubar.Menu

Prop Type Default Description
onOpenChange OnChangeFn<boolean> – A callback that is called when the menu is opened or closed.
value string – The value assigned to the menu. Used to programmatically control the menu's open state within the menubar.

Menubar.Trigger

Prop Type Default Description
disabled null | false | true false Whether the trigger for the menubar item is disabled.

Menubar.Content

Prop Type Default Description
align "start" | "center" | "end" 'start' The preferred alignment of the anchor to render against when open. This may change when collisions occur.
alignOffset number -4 An offset in pixels from the "start" or "end" alignment options.
arrowPadding number – This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners.
avoidCollisions boolean true When true, overrides the side and align options to prevent collisions with the boundary edges.
collisionBoundary Arrayable<Boundary> – A boundary element or array of elements to check for collisions against.
collisionPadding number | Partial<Record<"top" | "right" | "bottom" | "left", number>> 8 The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.
customAnchor string | HTMLElement | Measurable | null – Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement.
dir "ltr" | "rtl" – The text direction of the content.
escapeKeydownBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Escape behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press.
forceMount boolean – Whether to force mount the component.
hideWhenDetached boolean –
interactOutsideBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Interact outside behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to the parent element. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction.
loop boolean false When true, the menu will loop through items when navigating with the keyboard.
onCloseAutoFocus EventCallback – Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeydown ((e: KeyboardEvent) => void) – Callback fired when escape is pressed.
onFocusOutside ((event: FocusEvent) => void) – Callback fired when focus leaves the dismissible layer.
onInteractOutside InteractOutsideEventHandler – Callback fired when an outside interaction event completes, which is either a pointerup, mouseup, or touchend event, depending on the user's input device.
onOpenAutoFocus EventCallback – Event handler called when auto-focusing on open. Can be prevented.
portalProps PortalProps – Props for the portal the content renders in: to (the element to render in, the body by default) and disabled (render in place).
preventOverflowTextSelection boolean true Passing true will prevent the overflow of text selection outside the element, provided the element is the top layer.
preventScroll boolean true Whether to prevent scrolling the body when the content is open. Whether to prevent body scrolling when the content is open.
side "top" | "right" | "bottom" | "left" – The preferred side of the anchor to render against when open. Will be reversed when collisions occur.
sideOffset number 6 The distance in pixels from the anchor to the floating element.
sticky "partial" | "always" –
strategy "absolute" | "fixed" – The positioning strategy to use for the floating element.
trapFocus boolean false Whether focus is trapped within the focus scope.
updatePositionStrategy "always" | "optimized" "optimized" "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor.

Menubar.Portal

Prop Type Default Description
disabled boolean false Disable portalling and render the component inline
to PortalTarget document.body Where to portal the content to.

Menubar.Item

Prop Type Default Description
closeOnSelect boolean true Whether or not the menu item should close when selected.
disabled boolean false When true, the user will not be able to interact with the menu item.
inset boolean – Indent the text to line up with items that show an icon, check or dot.
onSelect ((event: Event) => void) – A callback fired when the menu item is selected. Prevent default behavior of selection with event.preventDefault().
textValue string undefined Optional text to use for typeahead filtering. By default, typeahead will use the .textContent of the menu item. When the content is more complex, you can provide a string here instead.
variant "error" | "default" 'default' error colours the item for deleting.

Menubar.CheckboxItem

Prop Type Default Description
checked bindable boolean false The checked state of the checkbox. It can be one of: - true for checked - false for unchecked
closeOnSelect boolean false Whether or not the menu item should close when selected.
disabled boolean false When true, the user will not be able to interact with the menu item.
indeterminate bindable boolean false Whether the checkbox is in an indeterminate state or not.
onCheckedChange OnChangeFn<boolean> – A callback that is fired when the checked state changes.
onIndeterminateChange OnChangeFn<boolean> – A callback function called when the indeterminate state changes.
onSelect ((event: Event) => void) – A callback fired when the menu item is selected. Prevent default behavior of selection with event.preventDefault().
textValue string undefined Optional text to use for typeahead filtering. By default, typeahead will use the .textContent of the menu item. When the content is more complex, you can provide a string here instead.
value string – The value of the checkbox item when used in a checkbox group.

Menubar.CheckboxGroup

Prop Type Default Description
onValueChange OnChangeFn<string[]> – A callback that is fired when the selected checkbox items change.
value bindable string[] [] The values of the selected checkbox items. Supports two-way binding with bind:value.

Menubar.RadioGroup

Prop Type Default Description
onValueChange OnChangeFn<string> – A callback that is fired when the selected radio item changes.
value bindable string '' The value of the selected radio item. Supports two-way binding with bind:value.

Menubar.RadioItem

Prop Type Default Description
closeOnSelect boolean false Whether or not the menu item should close when selected.
disabled boolean false When true, the user will not be able to interact with the menu item.
onSelect ((event: Event) => void) – A callback fired when the menu item is selected. Prevent default behavior of selection with event.preventDefault().
textValue string undefined Optional text to use for typeahead filtering. By default, typeahead will use the .textContent of the menu item. When the content is more complex, you can provide a string here instead.
value required string – The value of the radio item.

Menubar.Group

No props of its own beyond the common ones.

Menubar.GroupHeading

Prop Type Default Description
inset boolean – Indent the text to line up with items that show an icon, check or dot.

Menubar.Label

Prop Type Default Description
inset boolean – Indent the text to line up with items that show an icon, check or dot.

Menubar.Separator

No props of its own beyond the common ones.

Menubar.Shortcut

No props of its own beyond the common ones.

Menubar.Sub

Prop Type Default Description
onOpenChange OnChangeFn<boolean> – A callback that is called when the menu is opened or closed.
onOpenChangeComplete OnChangeFn<boolean> – A callback that is called when the menu finishes opening/closing animations.
open bindable boolean false The open state of the menu.

Menubar.SubTrigger

Prop Type Default Description
disabled boolean false When true, the user will not be able to interact with the menu item.
inset boolean – Indent the text to line up with items that show an icon, check or dot.
onSelect ((event: Event) => void) – A callback fired when the menu item is selected. Prevent default behavior of selection with event.preventDefault().
openDelay number 100 The amount of time in ms from when the mouse enters the subtrigger until the submenu opens. This is useful for preventing the submenu from opening as a user is moving their mouse through the menu without a true intention to open that submenu. To disable the behavior, set it to 0.
textValue string undefined Optional text to use for typeahead filtering. By default, typeahead will use the .textContent of the menu item. When the content is more complex, you can provide a string here instead.

Menubar.SubContent

Prop Type Default Description
align "start" | "center" | "end" – The preferred alignment of the anchor to render against when open. This may change when collisions occur.
alignOffset number – An offset in pixels from the "start" or "end" alignment options.
arrowPadding number – This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners.
avoidCollisions boolean true When true, overrides the side and align options to prevent collisions with the boundary edges.
collisionBoundary Arrayable<Boundary> – A boundary element or array of elements to check for collisions against.
collisionPadding number | Partial<Record<"top" | "right" | "bottom" | "left", number>> 8 The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.
customAnchor string | HTMLElement | Measurable | null – Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement.
dir "ltr" | "rtl" – The text direction of the content.
escapeKeydownBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Escape behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press.
forceMount boolean – Whether to force mount the component.
hideWhenDetached boolean –
interactOutsideBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Interact outside behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to the parent element. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction.
loop boolean false When true, the menu will loop through items when navigating with the keyboard.
onCloseAutoFocus EventCallback – Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeydown ((e: KeyboardEvent) => void) – Callback fired when escape is pressed.
onFocusOutside ((event: FocusEvent) => void) – Callback fired when focus leaves the dismissible layer.
onInteractOutside InteractOutsideEventHandler – Callback fired when an outside interaction event completes, which is either a pointerup, mouseup, or touchend event, depending on the user's input device.
onOpenAutoFocus EventCallback – Event handler called when auto-focusing on open. Can be prevented.
preventOverflowTextSelection boolean true Passing true will prevent the overflow of text selection outside the element, provided the element is the top layer.
side "top" | "right" | "bottom" | "left" – The preferred side of the anchor to render against when open. Will be reversed when collisions occur.
sideOffset number – The distance in pixels from the anchor to the floating element.
sticky "partial" | "always" –
strategy "absolute" | "fixed" – The positioning strategy to use for the floating element.
trapFocus boolean false Whether focus is trapped within the focus scope.
updatePositionStrategy "always" | "optimized" "optimized" "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor.