# Menubar (@limerdev/zest) A bar of menus, as in a desktop application: `` 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 `RadioItem`s, `Group` with `GroupHeading`, `Label`, `Separator` and submenus. Left and Right move between menus, Down opens one, Escape closes. - Category: Navigation - Import: `import { Menubar } from '@limerdev/zest'` - Bits UI: `Menubar`, https://bits-ui.com/docs/components/menubar - Exports: `Menubar.Root`, `Menubar.Menu`, `Menubar.Trigger`, `Menubar.Content`, `Menubar.Portal`, `Menubar.Item`, `Menubar.CheckboxItem`, `Menubar.CheckboxGroup`, `Menubar.RadioGroup`, `Menubar.RadioItem`, `Menubar.Group`, `Menubar.GroupHeading`, `Menubar.Label`, `Menubar.Separator`, `Menubar.Shortcut`, `Menubar.Sub`, `Menubar.SubTrigger`, `Menubar.SubContent` - 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`. ```svelte File New report ⌘N Export as CSV View Weekends ``` Props of `Menubar.Root`: - `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`): A callback that is called when the active menu changes. - `value` (`string`, default `''`, bindable): The 'value' assigned to the currently active menu in the menubar. Props of `Menubar.Menu`: - `onOpenChange` (`OnChangeFn`): 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. Props of `Menubar.Trigger`: - `disabled` (`null | false | true`, default `false`): Whether the trigger for the menubar item is disabled. Props of `Menubar.Content`: - `align` (`"start" | "center" | "end"`, default `'start'`): The preferred alignment of the anchor to render against when open. This may change when collisions occur. - `alignOffset` (`number`, default `-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`, default `true`): When `true`, overrides the `side` and `align` options to prevent collisions with the boundary edges. - `collisionBoundary` (`Arrayable`): A boundary element or array of elements to check for collisions against. - `collisionPadding` (`number | Partial>`, default `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"`, default `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"`, default `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`, default `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`, default `true`): Passing `true` will prevent the overflow of text selection outside the element, provided the element is the top layer. - `preventScroll` (`boolean`, default `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`, default `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`, default `false`): Whether focus is trapped within the focus scope. - `updatePositionStrategy` (`"always" | "optimized"`, default `"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. Props of `Menubar.Portal`: - `disabled` (`boolean`, default `false`): Disable portalling and render the component inline - `to` (`PortalTarget`, default `document.body`): Where to portal the content to. Props of `Menubar.Item`: - `closeOnSelect` (`boolean`, default `true`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `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`, default `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 `'default'`): `error` colours the item for deleting. Props of `Menubar.CheckboxItem`: - `checked` (`boolean`, default `false`, bindable): The checked state of the checkbox. It can be one of: - `true` for checked - `false` for unchecked - `closeOnSelect` (`boolean`, default `false`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `false`): When `true`, the user will not be able to interact with the menu item. - `indeterminate` (`boolean`, default `false`, bindable): Whether the checkbox is in an indeterminate state or not. - `onCheckedChange` (`OnChangeFn`): A callback that is fired when the checked state changes. - `onIndeterminateChange` (`OnChangeFn`): 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`, default `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. Props of `Menubar.CheckboxGroup`: - `onValueChange` (`OnChangeFn`): A callback that is fired when the selected checkbox items change. - `value` (`string[]`, default `[]`, bindable): The values of the selected checkbox items. Supports two-way binding with `bind:value`. Props of `Menubar.RadioGroup`: - `onValueChange` (`OnChangeFn`): A callback that is fired when the selected radio item changes. - `value` (`string`, default `''`, bindable): The value of the selected radio item. Supports two-way binding with `bind:value`. Props of `Menubar.RadioItem`: - `closeOnSelect` (`boolean`, default `false`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `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`, default `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`, required): The value of the radio item. Props of `Menubar.GroupHeading`: - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. Props of `Menubar.Label`: - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. Props of `Menubar.Sub`: - `onOpenChange` (`OnChangeFn`): A callback that is called when the menu is opened or closed. - `onOpenChangeComplete` (`OnChangeFn`): A callback that is called when the menu finishes opening/closing animations. - `open` (`boolean`, default `false`, bindable): The open state of the menu. Props of `Menubar.SubTrigger`: - `disabled` (`boolean`, default `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`, default `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`, default `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. Props of `Menubar.SubContent`: - `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`, default `true`): When `true`, overrides the `side` and `align` options to prevent collisions with the boundary edges. - `collisionBoundary` (`Arrayable`): A boundary element or array of elements to check for collisions against. - `collisionPadding` (`number | Partial>`, default `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"`, default `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"`, default `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`, default `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`, default `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`, default `false`): Whether focus is trapped within the focus scope. - `updatePositionStrategy` (`"always" | "optimized"`, default `"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. Example: Basic A report editor's commands. Left and Right move between menus. ```svelte File New report ⌘N Duplicate Export As CSV As PDF View Show weekends Group by Project Person Help Keyboard shortcuts ```