重要なコンテンツでユーザーを中断し、応答を期待するモーダルダイアログ。
import React from 'react';import * as AlertDialog from '@radix-ui/react-alert-dialog';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 your account and remove yourdata 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
` ボタンと視覚的に区別する必要があります。
ダイアログが開いたときにアナウンスされるアクセシブルな名前。代わりに、`aria-label
` または `aria-labelledby
` を `AlertDialog.Content
` に指定して、このコンポーネントを除外することもできます。
ダイアログが開いたときにアナウンスされるアクセシブルな説明。代わりに、`aria-describedby
` を `AlertDialog.Content
` に指定して、このコンポーネントを除外することもできます。
制御されたプロパティを使用して、非同期操作の完了後にアラートダイアログをプログラムで閉じます。
アラートダイアログがポータルされる要素をカスタマイズします。
アラートおよびメッセージダイアログのWAI-ARIAデザインパターンに準拠しています。