Skip to content

Menu Reference

This reference document covers the common menu item types and properties available in Wails v3. These features are shared between application menus and context menus.

Regular Menu Items

The most basic type of menu item displays text and triggers an action when clicked:

menuItem := menu.Add("Click Me")
menuItem.OnClick(func(ctx *application.Context) {
// Handle click
})

Checkboxes

Checkbox menu items provide a toggleable state:

checkbox := menu.AddCheckbox("Enable Feature", true) // true = initially checked
checkbox.OnClick(func(ctx *application.Context) {
isChecked := ctx.ClickedMenuItem().Checked()
// Handle state change
})

Radio Groups

Radio items create mutually exclusive options. Items are grouped automatically when placed adjacently:

menu.AddRadio("Option 1", true) // true = initially selected
menu.AddRadio("Option 2", false)
menu.AddRadio("Option 3", false)

Submenus allow you to create nested menu structures:

submenu := menu.AddSubmenu("More Options")
submenu.Add("Submenu Item 1")
submenu.Add("Submenu Item 2")

Separators

Separators add visual dividers between menu items:

menu.Add("Item 1")
menu.AddSeparator()
menu.Add("Item 2")

Label

The text displayed for the menu item:

menuItem := menu.Add("Initial Label")
menuItem.SetLabel("New Label")

Enabled State

Control whether the menu item can be interacted with:

menuItem := menu.Add("Disabled Item")
menuItem.SetEnabled(false)

Checked State

For checkbox and radio items, control or query their checked state:

checkbox := menu.AddCheckbox("Feature", false)
checkbox.SetChecked(true)
isChecked := checkbox.Checked()

Accelerators

Add keyboard shortcuts to menu items:

menuItem := menu.Add("Save")
menuItem.SetAccelerator("CmdOrCtrl+S")

Common accelerator modifiers:

  • CmdOrCtrl: Command on macOS, Control on Windows/Linux
  • Shift
  • Alt: Option on macOS
  • Ctrl: Control key on all platforms

Event Handling

Click Events

Handle menu item clicks using the OnClick method:

menuItem.OnClick(func(ctx *application.Context) {
// Access the clicked item
clickedItem := ctx.ClickedMenuItem()
// Get current state
label := clickedItem.Label()
isChecked := clickedItem.Checked()
// Update the item
clickedItem.SetLabel("New Label")
})

Shared Event Handlers

Event handlers can be shared amongst multiple menu items:

handleClick := func(ctx *application.Context) {
item := ctx.ClickedMenuItem()
// Common handling logic
}
menu.Add("Item 1").OnClick(handleClick)
menu.Add("Item 2").OnClick(handleClick)

Dynamic Updates

Menu items can be updated dynamically during runtime:

menuItem := menu.Add("Initial State")
// Later, update the item
menuItem.SetLabel("New Label")
menuItem.SetEnabled(false)
menuItem.SetChecked(true)
// Apply changes
menu.Update()

Best Practices

  1. Use clear, concise labels that describe the action
  2. Group related items together using separators
  3. Limit submenu depth to maintain usability
  4. Provide keyboard shortcuts for common actions
  5. Keep radio groups focused on a single choice
  6. Update menu items to reflect application state
  7. Handle all possible states in click handlers

Platform Considerations