Menu
ui.widgets.MenuContextual 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.
// ── 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;
}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.
MenuProps
ui.widgets.Menufn Menu(props: MenuProps) MenuBuilderField
Type
Default
Description
items[]const MenuItem&.{}—
on_select?core.HandlerRefnull—
widthf32220—
positionpopover_mod.PopoverPosition.bottom_start—
MenuResult
ui.widgets.MenuField
Type
Default
Description
wrapper*Node—
—
trigger*Node—
—
state*MenuState—
—