Modal / 对话框
弹出显示需要额外注意或重要的内容。如果你仅需要提示文本信息,请考虑 Toast 组件。
对话框组件包含额外的 Hooks,详情请参阅 useModal 小节。
基础的
使用 visible
属性控制何时显示对话框。
无按钮
隐藏指定的按钮。
禁用按钮
禁用指定的按钮。
定制化
自定义 width
或是 className
。
加载中
APIs / 接口文档
Modal.Props
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
visible | 打开或关闭对话框 | boolean | - | false |
onClose | 关闭的事件 | () => void | - | - |
onContentClick | 对话框内部点击事件 | (e: MouseEvent) => void | - | - |
wrapClassName | 对话框的自定义样式类名 | string | - | - |
keyboard | 按下 Esc 键关闭对话框 | boolean | - | true |
disableBackdropClick | 点击背景层时是否关闭对话框 | boolean | - | false |
... | 原生属性 | HTMLAttributes | 'autoFocus', 'name', 'className', ... | - |
Modal.Title.Props
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
... | 原生属性 | HTMLAttributes | 'id', 'className', ... | - |
Modal.Subtitle.Props
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
... | 原生属性 | HTMLAttributes | 'id', 'className', ... | - |
Modal.Content.Props
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
... | 原生属性 | HTMLAttributes | 'id', 'className', ... | - |
Modal.Action.Props
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
passive | 以消极的状态显示按钮 | boolean | - | false |
disabled | 禁用按钮 | boolean | - | false |
onClick | 按钮的点击事件 | (event: ModalActionEvent) => void | - | - |
loading | 显示加载状态指示器 | boolean | - | false |
... | 原生属性 | ButtonHTMLAttributes | 'id', 'className', ... | - |
useModal
type useModal = (initialVisible: boolean) => {
visible: boolean
setVisible: Dispatch<SetStateAction<boolean>>
currentRef: MutableRefObject<boolean>
bindings: {
visible: boolean
onClose: () => void
}
}
ModalActionEvent
type ModalActionEvent = MouseEvent<HTMLButtonElement> & {
close: () => void
}
文档贡献者