components/menu
Navigation · 37 / 64

Menu

ui.widgets.Menu

Contextual actions with shortcut hints.

BEHAVIOR CONTRACT

Trigger, portal, separators, danger items, outside dismiss and Escape ship together.

RECORDED INTERACTION

The harness opens the Actions menu: Cut / Copy / Delete.

examples/storybook/stories.zig:2335
// ── Menu(trigger+popover:item 在弹层里,story 给 trigger 加按钮,e2e 点开验 item)──
pub fn buildMenu(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 8);
    try c.appendChild(a, try label(cx, "Click the trigger to open the menu"));
    const items = [_]W.MenuItem{
        .{ .id = "cut", .label_text = "Cut", .shortcut = "⌘X" },
        .{ .id = "copy", .label_text = "Copy", .shortcut = "⌘C" },
        .{ .id = "sep", .kind = .separator },
        .{ .id = "del", .label_text = "Delete", .danger = true },
    };
    const m = try W.Menu(.{ .items = &items }).mount(scope, cx);
    // 给 trigger 放一个有标签的按钮,让 story 可见可点
    try m.trigger.appendChild(a, try W.Button(.{ .label = "Actions ▾", .variant = .secondary }).mount(scope, cx));
    m.wrapper.meta.ownership.meta.test_id = "story.menu.trigger";
    try c.appendChild(a, m.wrapper);
    return c;
}
View source on GitHubexamples/storybook/stories.zig:2335

The story's verbatim source from the Storybook (zenit 4c50245 2026-10-01). W is ui.widgets; col / row / label are small Storybook layout helpers.

zenit · Dual-licensedFree for open-source projects under GPL-3.0-only; closed-source or commercial products need a commercial license.Contact the author: zongyi.xzy#gmail.com (replace # with @)zenit 4c50245 2026-10-01