# Dialog · 模态对话框

用 `open` 控制对话框的可见性，通过 `onOpenChange` 接收关闭请求。屏幕阅读器使用 `title` 作为对话框名称。简短的操作说明放入 `description`，较长的内容及表单放入子节点，确认按钮放入 `footer`。

```tsx
'use client'

import { useState } from 'react'
import { Button, Dialog } from '@ancrel/ui'
import '@ancrel/tokens/css'
import '@ancrel/ui/styles.css'

export default function App() {
  const [open, setOpen] = useState(false)
  const [busy, setBusy] = useState(false)
  return <>
    <Button onClick={() => setOpen(true)}>Review changes</Button>
    <Dialog open={open} onOpenChange={setOpen} busy={busy} title="Publish changes"
      description="Review the summary before publishing."
      footer={<Button onClick={() => setBusy(!busy)}>{busy ? 'Finish' : 'Start review'}</Button>}>
      <p>Two pages have changed.</p>
    </Dialog>
  </>
}
```

Expected:

### Expected behavior

Open **Review changes**. The dialog is named **Publish changes** and describes the review. **Start review** locks dismissal. Choose **Finish** to release the lock, then press Escape to close.

## 等待操作完成

提交时把 `busy` 绑定到请求状态，这将阻止 Escape、遮罩按下和关闭按钮。由调用方在成功后更新 `open`，在失败后清除 `busy` 并显示错误信息。自行提供的页脚按钮也应根据请求状态控制重复提交。

打开时焦点进入对话框，Tab 和 Shift+Tab 在其中循环。若从抽屉内再打开对话框，按一次 Escape 只关闭当前对话框，并将焦点还给抽屉内的触发控件。

`--ac-sys-layer-modal`

| `Context` | `--ac-sys-layer-modal` |
| - | - |
| `dark/compact` | `30` |
| `dark/comfortable` | `30` |
| `light/compact` | `30` |
| `light/comfortable` | `30` |

| `Prop` | `Type` | `Required` | `Default` |
| - | - | - | - |
| `busy` | `boolean` | `false` | `—` |
| `children` | `ReactNode` | `false` | `—` |
| `className` | `string` | `false` | `—` |
| `description` | `ReactNode` | `false` | `—` |
| `footer` | `ReactNode` | `false` | `—` |
| `key` | `React.Key \| null \| undefined` | `false` | `—` |
| `onOpenChange` | `(open: boolean) => void` | `true` | `—` |
| `open` | `boolean` | `true` | `—` |
| `ref` | `React.Ref<HTMLDivElement> \| undefined` | `false` | `—` |
| `title` | `ReactNode` | `true` | `—` |

```ts
import * as React from 'react';
import type { DialogProps } from './types.js';
export declare const Dialog: React.ForwardRefExoticComponent<DialogProps & React.RefAttributes<HTMLDivElement>>;
```

* default — dark/compact, dark/comfortable, light/compact, light/comfortable
