Skip to content

Menu: action lists

Build action lists with Menu. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"fmt"
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	value := ""
	actions := 0
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Menu",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Box(
				dxui.BoxProps{
					Gap: 12,
				},
				dxui.Menu(dxui.MenuProps{
					Value: value,
					Items: []dxui.MenuItem{
						{
							Value: "save",
							Label: "Save",
						},
						{
							Value: "export",
							Label: "Export",
						},
					},
					OnAction: func(v string) {
						value = v
						actions++
					},
				}),
				dxui.Label(fmt.Sprintf("%s: %d actions", value, actions)),
			),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Menu(props MenuProps) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
OrientationMenuOrientationDefaults to vertical; see behavior below.
ValuestringCurrent application-owned value; see this page for behavior and zero-value semantics.
Items[]MenuItemCopied item list with nonempty unique values; may be empty.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
OnActionfunc(string)Receives Value whenever an enabled item executes; the same item may execute repeatedly.

Behavior and limitations

An action list within normal layout. Defaults to MenuVertical; MenuHorizontal selects horizontal. Value optionally controls selected appearance; OnAction still fires for an already-selected item. Item.Value must be nonempty and unique. One menu contributes one Tab stop. Orientation-specific arrows/Home/End move the internal current item without wrapping; Enter/Space executes. No built-in popup, submenus, separators, routing, or shortcut fields. Compose long menus with Scroll.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.