Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Menu

Vizia menus are built from three views:

  • MenuBar for top-level horizontal menu groups.
  • Submenu for nested menu popups.
  • MenuButton for actionable leaf items.

When To Use It

Use menu views for command-heavy desktop interfaces where users expect grouped actions (for example File/Edit/View) and nested command hierarchies.

Constructing Menus

Top-level menubar with a submenu and menu buttons:

MenuBar::new(cx, |cx| {
	Submenu::new(
		cx,
		|cx| Label::new(cx, "File"),
		|cx| {
			MenuButton::new(
				cx,
				|cx| cx.emit(AppEvent::NewProject),
				|cx| Label::new(cx, "New"),
			);

			MenuButton::new(
				cx,
				|cx| cx.emit(AppEvent::OpenProject),
				|cx| Label::new(cx, "Open"),
			);
		},
	);
});

Nested submenu:

Submenu::new(
	cx,
	|cx| Label::new(cx, "Export"),
	|cx| {
		MenuButton::new(
			cx,
			|cx| cx.emit(AppEvent::ExportPng),
			|cx| Label::new(cx, "PNG"),
		);
	},
);

API Notes

  • MenuBar::new(cx, content) manages top-level open/close behavior.
  • Submenu::new(cx, content, menu) renders a pressable row and popup content.
  • MenuButton::new(cx, action, content) triggers action and closes open menus.
  • Menu open state is coordinated with MenuEvent::{Open, Close, CloseAll, ToggleOpen}.

Components and Styling

SelectorDescription
menubarRoot element for top-level horizontal menus.
menuPopup container holding the list of menu items.
submenuPressable row that controls submenu popup.
submenu .arrowChevron shown for submenu rows.
menubuttonPressable leaf action item.
submenu:checkedOpen/checked submenu state.

Accessibility

  • MenuButton uses role MenuItem and is keyboard navigable.
  • Keep menu labels concise and ensure command text is descriptive.
  • Close menus after command activation for predictable focus behavior.

Keyboard Interaction

When a menu popup is open:

KeyAction
ArrowDown / ArrowUpMove focus to the next/previous menu item.
Home / EndMove focus to the first/last menu item.
ArrowLeftClose the current submenu level (or move toward parent menu context).
EscapeClose the active menu and return focus to the trigger.
TabClose all open menus and continue normal focus traversal.

When focus is on a submenu trigger row:

KeyAction
ArrowDown / Enter / SpaceOpen the submenu.
ArrowRightNavigate/open submenu to the right when applicable.