v0.1.0-alpha
官网Home
components/dropdown
导航Navigation · 38 / 64

DropdownMenu

ui.widgets.DropdownMenu

从按钮展开的一组命令。A set of commands opened from a button.

BEHAVIOR CONTRACT

item kind、shortcut、选择回调、浮层定位和 dismiss 行为统一管理。Item kinds, shortcuts, selection callbacks, positioning and dismissal are managed together.

RECORDED INTERACTION

Harness 打开 File 菜单并展示 New / Open / Save。The harness opens the File menu: New / Open / Save.

examples/storybook/stories.zig:2354
// ── DropdownMenu(同 Menu:trigger+popover)──
pub fn buildDropdownMenu(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 dropdown"));
    const items = [_]W.DropdownItem{
        .{ .id = "new", .label_text = "New File" },
        .{ .id = "open", .label_text = "Open…" },
        .{ .id = "sep", .kind = .separator },
        .{ .id = "save", .label_text = "Save" },
    };
    const dm = try W.DropdownMenu(.{ .items = &items }).mount(scope, cx);
    try dm.trigger.appendChild(a, try W.Button(.{ .label = "File ▾", .variant = .secondary }).mount(scope, cx));
    dm.wrapper.meta.ownership.meta.test_id = "story.dropdown.trigger";
    try c.appendChild(a, dm.wrapper);
    return c;
}
在 GitHub 查看源码View source on GitHubexamples/storybook/stories.zig:2354

这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。The story's verbatim source from the Storybook (zenit 5f9add5+wip 2026-09-30). W is ui.widgets; col / row / label are small Storybook layout helpers.

zenit · 双授权Dual-licensed开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。Free 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 5f9add5+wip 2026-09-30