DropdownMenu
ui.widgets.DropdownMenu버튼에서 열리는 명령 모음.
BEHAVIOR CONTRACT
item kind, 단축키, 선택 콜백, 오버레이 위치, dismiss 동작을 함께 관리합니다.
RECORDED INTERACTION
harness가 File 메뉴를 열어 New / Open / Save를 보여 줍니다.
// ── 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;
}Storybook에 있는 이 story의 원본 코드입니다(zenit 5f9add5+wip 2026-09-30). W는 ui.widgets이며, col / row / label은 Storybook 내부의 작은 레이아웃 헬퍼입니다.
DropdownMenuProps
ui.widgets.DropdownMenufn DropdownMenu(props: DropdownMenuProps) DropdownMenuBuilder필드
타입
기본값
설명
items[]const DropdownItem&.{}菜单项列表. mount copies the item records and their string fields, so callers may pass a function-local array. Handler contexts still follow the normal Scope lifetime contract.
widthf32220面板宽度
positionpopover_mod.PopoverPosition.bottom_start弹出位置
max_height?f32null可选的菜单最大高度。设置后复用 Popover 的原生 fit_or_scroll/ScrollArea。
DropdownMenuResult
ui.widgets.DropdownMenu필드
타입
기본값
설명
wrapper*Node—
外层包裹节点
trigger*Node—
trigger 插槽(调用方在此插入触发元素)
state*DropdownMenuState—
内部状态(可用于外部控制)