一个中断用户的重要内容并期待回应的模态对话框。
import * as React from "react";import { AlertDialog } from "radix-ui";import "./styles.css";const AlertDialogDemo = () => (<AlertDialog.Root><AlertDialog.Trigger asChild><button className="Button violet">Delete account</button></AlertDialog.Trigger><AlertDialog.Portal><AlertDialog.Overlay className="AlertDialogOverlay" /><AlertDialog.Content className="AlertDialogContent"><AlertDialog.Title className="AlertDialogTitle">Are you absolutely sure?</AlertDialog.Title><AlertDialog.Description className="AlertDialogDescription">This action cannot be undone. This will permanently delete youraccount and remove your data from our servers.</AlertDialog.Description><div style={{ display: "flex", gap: 25, justifyContent: "flex-end" }}><AlertDialog.Cancel asChild><button className="Button mauve">Cancel</button></AlertDialog.Cancel><AlertDialog.Action asChild><button className="Button red">Yes, delete account</button></AlertDialog.Action></div></AlertDialog.Content></AlertDialog.Portal></AlertDialog.Root>);export default AlertDialogDemo;
焦点会被自动捕获。
可以是受控或非受控。
使用 Title
和 Description
组件来管理屏幕阅读器通知。
按 Esc 键会自动关闭组件。
可以从命令行中安装该组件。
导入所有部分并将其组合在一起。
包含警告对话框的所有部分。
一个打开对话框的按钮。
使用时,将您的覆盖层和内容部分传送到 body
中。
对话框打开时覆盖视图的无效部分的层。
包含在对话框打开时要呈现的内容。
一个关闭对话框的按钮。该按钮应该在视觉上与 AlertDialog.Action
按钮区分开来。
一个关闭对话框的按钮。这些按钮应该在视觉上与 AlertDialog.Cancel
按钮区分开来。
打开对话框时将被宣布的可访问名称。或者,您可以为 AlertDialog.Content
提供 aria-label
或 aria-labelledby
,并排除此组件。
打开对话框时将被宣布的可访问描述。或者,您可以为 AlertDialog.Content
提供 aria-describedby
,并排除此组件。
使用受控属性在异步操作完成后以编程方式关闭警告对话框。
自定义您的警告对话框门户的元素。