components/modal
Overlays · 42 / 64

Modal

ui.widgets.Modal

Blocking tasks, confirmations and focused context.

BEHAVIOR CONTRACT

Window-root portal, barrier, focus, Escape, inside / outside hit-testing and the entrance animation are guaranteed together.

RECORDED INTERACTION

The harness opens the centered dialog and hovers inside it without dismissing.

examples/storybook/stories.zig:2504
pub fn buildModal(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);
    const vis = try scope.createSignal(bool, false);
    const st = try cx.bindState(ModalStory, .{ .visible = vis });
    const btn = try W.Button(.{ .label = "Open Modal", .on_click = cx.on(ModalStory, st, ModalStory.open) }).mount(scope, cx);
    btn.meta.ownership.meta.test_id = "story.modal.open";
    try c.appendChild(a, btn);

    const m = try W.Modal(.{ .title = "Example Modal", .width = 400 }).visible(vis).mount(scope, cx);
    m.dialog.meta.ownership.meta.test_id = "story.modal.dialog";
    try m.body.appendChild(a, try ui.text(cx, "Modal body content.", .{ .font_size = 14, .color = light.color.fg_primary }));
    // 带 hover 样式的按钮:damage-rect e2e 用它触发"层内小块变化 -> 部分重绘"
    const ok_btn = try W.Button(.{ .label = "OK" }).mount(scope, cx);
    ok_btn.meta.ownership.meta.test_id = "story.modal.ok";
    try m.body.appendChild(a, ok_btn);
    // portaled 时 overlay 已挂到 window-root portal(覆盖整窗口);未 portal 时才内联。
    if (!m.portaled) try c.appendChild(a, m.overlay);
    return c;
}
View source on GitHubexamples/storybook/stories.zig:2504

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.

zenit · Dual-licensedFree 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 4c50245 2026-10-01