Menubar

View as Markdown

File, Edit and View along the top of an editor: menus the arrow keys move through as one control.

Q1 launch plan. Pricing moves to seats on 1 February; the migration email goes out a week before.

Zoom 100% · Ruler on

When to use

File, Edit and View along the top of an editor: menus the arrow keys move through as one control. Use Menu instead when the app needs one menu, not a row of them.

Usage

import { Menubar, MenubarState } from "./ui/uicontext/components/Menubar.ts"
const Message = UiSchema.TaggedEnum({ ChangedMenus: { state: MenubarState }, Picked: { value: Schema.String } })export const AppMenus = (h: Html.H<typeof Message.Type>, state: MenubarState) =>	Menubar(h, {		label: "App",		menus: [			{ name: "File", entries: [{ _tag: "Item", value: "new", label: "New", shortcut: "mod+n" }] },			{ name: "Edit", entries: [{ _tag: "Item", value: "undo", label: "Undo", shortcut: "mod+z" }] },		],		state,		onState: (next) => Message.ChangedMenus({ state: next }),		onSelect: (event) => (event._tag === "RequestedPick" ? Message.Picked({ value: event.value }) : undefined),	})

Examples

Framed, with a disabled menu

framed draws the bar on a surface of its own. A menu with disabled stays in the bar and is skipped by the keys.

API reference

MenubarView function

Options

Menubar options
NameTypeDescription
keystringNames the menubar among others in the same view; needed for more than one.
labelrequiredstringWhat the bar is for: "Editor".
menusrequiredMenubarMenu[]—
staterequiredMenubarState—
onStaterequired(state: MenubarState) => Message—
onSelectrequired(event: typeof MenuEvents.Type, menu: string) => MessageAn action picked, a checkbox toggled or a radio option chosen, with the menu it was in.
framedbooleanA border and a surface around the bar.
disabledboolean—
styleStyle—

MenuComponent

Props

Menu props
NameTypeDescription
labelrequiredstringThe button's text, and its accessible name
entriesrequiredMenuEntry[]The menu's actions, checkbox and radio items, separators, labels and submenus, in order
iconOnlybooleanShow only an icon on the button (the label still names it): "⋯" by default
iconstringThe icon the button shows instead of its label, by name; "chevron" draws a down chevron
emphasis"outline" | "ghost"Outline (the default) or ghost, as Button's
size"xs" | "sm" | "md""xs": a 24px icon button, for a row's or a block's actions
align"start" | "end"Which edge of the button the menu lines up with
disabledbooleanThe button can't open the menu
tabbablebooleanFalse for a row's menu that its row opens from the keyboard (Shift+F10): the button leaves the Tab order, so a long list isn't a Tab stop per row

Events

Menu events
EventPayloadDescription
RequestedPick{ value: string }An action was picked
RequestedToggle{ value: string; checked: boolean }A checkbox item asks for checked
RequestedPickRadio{ group: string; value: string }A radio item asks for value in its group

MenuPreviewView function

Options

MenuPreview options
NameTypeDescription
entriesrequiredMenuEntry[]The items to draw, as Menu takes them
highlightedstringThe value of the item drawn as highlighted, as if the pointer were on it

MenuRowsView function

Options

MenuRows options
NameTypeDescription
submenurequiredstring | nullThe value of the submenu that's open, or null
pickrequired(value: string, checked: boolean | undefined) => Message—
openSubmenurequired(value: string) => Message—
closeSubmenurequired(value: string) => Message—

Keyboard and accessibility

KeysDoes
Right arrow Left arrowMove along the bar; in an open menu, open the next or the previous one
Home EndGo to the first or the last menu
Enter Space Down arrowOpen the menu
Down arrow Up arrowMove between items
a letterJump to the next item that starts with what’s typed
EscapeClose the menu and put focus back on its name

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/menubar

Source