Skip to content

Delete confirmation and undo patterns for shadcn

Rules / Destructive actions: 2 rules and 0 guidelines

Deleting a file, archiving a project, cancelling a subscription, sending money: some actions take something away, and the way an app handles them decides whether a slip of the hand costs a second or a day’s work. The common reflex is to put an “Are you sure?” dialog in front of every one of them. The rules here point another way: make the action safe to undo, and save the question for the few cases where it cannot be.

Where it goes wrong

  • A confirmation before every delete, even of a draft that could be restored. People learn to press the confirming button without reading, and the one question that matters gets the same quick yes. DST-001b
  • No way back after a delete that the product could easily have kept, for example by moving the item to a bin first. DST-001a
  • Undo that exists only in a toast which disappears after a few seconds. FBK-005
  • A confirmation that says OK, puts focus on the destructive button, or looks like any other dialog. DLG-003, and the guidelines DLG-004 and DLG-005 (our choice)

How the rules fit together

DST-001a comes first. Wherever the product can make an action reversible, it should. When an action can be fully reversed, it runs at once and Undo is offered right after it. That covers most deletes in a typical app: rows in a table, files, messages, labels.

DST-001b decides when a question is still right. Ask only when the step cannot be reversed and destroys, spends or commits something of value, or when a mistake would be costly and hard to put right, such as a charge to a card. Never ask before anything else. The two rules meet on purpose: a routine action that Undo fully reverses never gets a confirmation.

When a confirmation is needed, the dialog patterns say how it works. The button names the action, such as “Delete project”, and Cancel is always there (DLG-003). Two guidelines, our choice, add that focus starts on Cancel (DLG-004) and that the destructive button has the danger style (DLG-005). In shadcn, that dialog is AlertDialog. Radix builds it so that a press on the backdrop does not close it and focus starts on Cancel; the words, the style and the decision to ask at all are yours.

The Undo itself is feedback, so the feedback patterns apply. A toast that offers Undo holds only that one action, stays until it is used or closed, and the same action can be found somewhere that lasts (FBK-005). Once the action has run, the item shows its new state in the view (FBK-003).

A useful test for any destructive flow: delete something by mistake, on purpose, with the keyboard only. Count how many steps it takes to get it back, and whether you could have stopped it before it happened without reading every word.

What WCAG requires and what the judges decide

No WCAG 2.2 criterion requires either rule. Both support 3.3.4 Error Prevention (Legal, Financial, Data), which applies to some legal, financial and data submissions, but they reach further than that criterion, so the judges decide them. Making actions reversible and offering Undo had both judges who spoke in support. Asking only when a step cannot be reversed or would cost a lot had all three. The rules for the confirmation dialog itself are under Dialogs, where two of them are guidelines.

Rules and guidelines

Each one has its own page with the full rule, Do and Don't cases, exceptions and the verdict. A rule is decided by WCAG 2.2 or by the judges. A guideline is our own choice. How the method works

Decided by the judges

No WCAG criterion requires these. The judges who spoke support them, all or most of them.

All rules · Is shadcn accessible? · Give the rules to an AI agent

Justified by Blackwood & Blake helps you work toward WCAG 2.2 AA. It is not a certification. Read more