Menu
ui.widgets.Menuショートカットのヒント付きのコンテキストアクション一覧。
BEHAVIOR CONTRACT
trigger、portal、separator、danger item、外側クリックでの dismiss、Escape を一式で実装しています。
RECORDED INTERACTION
harness が Actions メニューを開き、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;
}Storybook にあるこの story のコードそのままです(zenit 5f9add5+wip 2026-09-30)。W は ui.widgets のことで、col / row / label は Storybook 内の小さなレイアウトヘルパーです。
MenuProps
ui.widgets.Menufn Menu(props: MenuProps) MenuBuilderフィールド
型
デフォルト値
説明
items[]const MenuItem&.{}—
on_select?core.HandlerRefnull—
widthf32220—
positionpopover_mod.PopoverPosition.bottom_start—
MenuResult
ui.widgets.Menuフィールド
型
デフォルト値
説明
wrapper*Node—
—
trigger*Node—
—
state*MenuState—
—