---
title: "Modal コンポーネント — zenit Zig UI"
description: "ブロッキングなタスク、確認、集中すべきコンテキスト。window-root portal、barrier、フォーカス、Escape、inside / outside のヒット…"
url: https://zenit.z.express/ja/components/modal
language: ja
alternate_en: https://zenit.z.express/components/modal.md
alternate_zh: https://zenit.z.express/zh/components/modal.md
alternate_es: https://zenit.z.express/es/components/modal.md
alternate_ko: https://zenit.z.express/ko/components/modal.md
alternate_fr: https://zenit.z.express/fr/components/modal.md
alternate_de: https://zenit.z.express/de/components/modal.md
project: zenit v0.1.0-alpha (Zig 0.15.2, macOS)
source: https://github.com/version-next/zenit
---

# Modal

`ui.widgets.Modal`

ブロッキングなタスク、確認、集中すべきコンテキスト。

[Video](https://zenit.z.express/media/stories/modal.mp4?v=f1b080996c)

**BEHAVIOR CONTRACT**

window-root portal、barrier、フォーカス、Escape、inside / outside のヒットテスト、入場アニメーションをまとめて保証します。

**RECORDED INTERACTION**

harness が中央のダイアログを開き、内部のボタンに hover しても閉じないことを確認します。

`examples/storybook/stories.zig:2504`

```zig
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;
}
```

[GitHub でソースを見るexamples/storybook/stories.zig:2504](https://github.com/version-next/zenit/blob/HEAD/examples/storybook/stories.zig#L2504)

Storybook にあるこの story のコードそのままです（zenit 5f9add5+wip 2026-09-30）。`W` は `ui.widgets` のことで、`col` / `row` / `label` は Storybook 内の小さなレイアウトヘルパーです。

### ModalProps

`ui.widgets.Modal`

[src/ui/components/modal/mod.zig:25](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/modal/mod.zig#L25)

```zig
fn Modal(props: ModalProps) ModalBuilder
```

| フィールド | 型 | デフォルト値 | 説明 |
| --- | --- | --- | --- |
| `title` | `?[]const u8` | `null` | 标题 |
| `width` | `f32` | `480` | 宽度 |
| `max_height` | `f32` | `600` | 最大高度 |
| `overlay_color` | `?Color` | `null` | 遮罩颜色 (null = 使用主题 overlay) |
| `background` | `?Color` | `null` | 对话框背景 |
| `close_on_overlay` | `bool` | `true` | 点击遮罩关闭 |
| `visible` | `?*Signal(bool)` | `null` | 显示控制 Signal（外部传入） |
| `close_icon_asset` | `?svg_assets.Asset` | `null` | 关闭按钮 SVG 资产（可选，null 则回退文本 ✕） |

### ModalResult

`ui.widgets.Modal`

[src/ui/components/modal/mod.zig:63](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/modal/mod.zig#L63)

| フィールド | 型 | デフォルト値 | 説明 |
| --- | --- | --- | --- |
| `overlay` | `*Node` | — | — |
| `dialog` | `*Node` | — | — |
| `body` | `*Node` | — | — |
| `portaled` | `bool` | — | — |
