组件

Alert Dialog

A dialog that asks one question and will not go away until it is answered: no close button, no dismissing by clicking outside, focus starts on the safe answer. For risky questions it can be taped with hazard strips and given a red patch behind its icon.

安装

terminal
npx shadcn@latest add @wobko/alert-dialog

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Delete (danger)

The risky question: hazard tape across the top corners, a red patch behind the icon, and a hatched destructive answer. Focus starts on Cancel.

Small

size="sm": a narrow, centered sheet with the two answers in equal columns. Good for quick confirmations.

Media tones

The round patch behind the media says what kind of question this is: highlighter for a plain confirmation, sky for information, red pencil for danger.

Async action (controlled)

A confirmation that does real work: the action keeps the dialog open while it runs (preventDefault), disables both answers, then closes it and the page reports the result.

Are you absolutely sure?

The shadcn demo with no extras: an outline trigger, a title, one paragraph and the two answers. Focus starts on Cancel, Escape closes it, a click on the backdrop does not, and focus returns to the trigger.

API 参考

AlertDialogContent

The sheet: a Paper that is also the alertdialog. It takes every Radix Content prop and these.

属性类型默认值说明
size"default" | "sm""default"`sm` is a narrow, centered sheet with the buttons in two equal columns.
tone"default" | "danger""default"`danger` tapes red-and-white hazard strips across the top corners.
stockStockName"paper"What the sheet is made of.
edgeEdgeSpec"cut"Cut (CSS, no svg), torn, deckle, ...
tiltboolean | numbertrueSmall seeded tilt of the sheet; text stays upright; phones lay it flat.
seedstring | number-Pins the hand.

AlertDialogMedia

The picture beside the question: put an Icon or a Sticker in it. It sits on a hand-drawn round patch.

属性类型默认值说明
tone"default" | "danger" | "info""default"The patch color: highlighter, red pencil wash, sky.
seedstring | number-Pins the hand.

AlertDialogAction

The confirming answer. A Button (asChild over Radix Action) that closes the dialog after its onClick.

属性类型默认值说明
variantButtonVariant"default"Any Button variant; use `destructive` for irreversible actions.
sizeButtonSize"default"Any Button size.

AlertDialogCancel

The safe answer. A Button that closes the dialog; focus starts here.

属性类型默认值说明
variantButtonVariant"outline"Any Button variant.
sizeButtonSize"default"Any Button size.

无障碍

  • Radix AlertDialog: role=alertdialog with `aria-labelledby` and `aria-describedby` (always provide a title and description). Focus is trapped, the page behind is inert, and Escape cancels.
  • Focus starts on the Cancel button, so an accidental Enter does the safe thing. Clicking outside does not dismiss it.
  • The hazard tape and the media patch are decoration; the meaning is in the words and in the destructive button (hatched, not only red).
  • With reduced motion the sheet simply appears; in `calm` density it is flat and untaped.

源码

CLI 会复制进你项目的文件。

正在加载源码