components/menu
Navegación · 37 / 64

Menu

ui.widgets.Menu

Acciones contextuales con atajos de teclado.

BEHAVIOR CONTRACT

Disparador, portal, separadores, elementos peligrosos, cierre al hacer clic fuera y Escape vienen juntos.

RECORDED INTERACTION

El harness abre el menú Actions: 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;
}
Ver el código en GitHubexamples/storybook/stories.zig:2335

El código literal de la story en el Storybook (zenit 5f9add5+wip 2026-09-30). W es ui.widgets; col / row / label son pequeños helpers de layout del Storybook.

zenit · Doble licenciaGratis para proyectos de código abierto bajo GPL-3.0-only; los productos cerrados o comerciales necesitan una licencia comercial.Contacta con el autor: zongyi.xzy#gmail.com (cambia # por @)zenit 5f9add5+wip 2026-09-30