Modal
ui.widgets.Modal阻塞式任务、确认与聚焦上下文。Blocking tasks, confirmations and focused context.
BEHAVIOR CONTRACT
window-root portal、barrier、焦点、Escape、inside / outside hit-test 和入场动画一起保证。Window-root portal, barrier, focus, Escape, inside / outside hit-testing and the entrance animation are guaranteed together.
RECORDED INTERACTION
Harness 打开居中 dialog,并悬停内部按钮验证不会误关。The harness opens the centered dialog and hovers inside it without dismissing.
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;
}这是 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.