Destructive actions

Undo over confirm: make a destructive action reversible and offer Undo, and confirm only what cannot be taken back.

Make a destructive action reversible and offer Undo afterwards, rather than asking first. Confirm only the step that cannot be undone, and say exactly what it destroys.

  • Touch sizes for the toolbar icons
  • Release 0.9.0: changelog draft
  • Flaky test: retry-once times out on the slow runner
  • Search on the docs site ranks the Storybook pages too high
Trash: empty

Mail's conversations, as in the Mail demo. Archiving one, or deleting it into Trash, happens at once, with Undo in the toast: nothing is lost yet, so nothing is asked. Delete forever… cannot be undone, so it is the one step that asks, naming the conversation or how many go, and pointing at the way to keep them. A conversation that goes takes its button's focus with it, so the same button on the row now in its place takes it, as Accessibility asks.

Do and don't#

Delete 3 conversations forever?

They cannot be restored. To keep them, move them back to the inbox instead.

Do

Ask a question that names the thing and the count, and label the button with the same verb: Delete 3 conversations.

Are you sure?

This action cannot be undone.

Don't

Ask "Are you sure?" with OK: people learn to press it without reading.

Touch sizes for the toolbar icons
Do

Archive, move to the trash or hide, and toast with Undo. The fast path stays fast and a slip costs one tap.

Touch sizes for the toolbar icons
Don't

Confirm every delete. A dialog on each one teaches people to click through it, so it no longer protects the one delete that mattered.

Which safeguard#

The actionCan it be reversed?Safeguard
Archive, hide, move to the trash, remove from a listYesDo it, toast with Undo
Remove a past query from a search box's historyYes, by searching it againDo it, with no toast, see Search
Delete, where the app keeps a trash or historyYes, from thereDo it, toast with Undo and say where it went
Discard unsaved edits by leavingNoUnsavedChangesDialog, see Forms
Delete for good, empty the trash, revoke a tokenNoConfirmDialog with destructive
Delete something large or shared that others rely onNoConfirmDialog, and say what else goes with it
  • ci-runnerRead and write runs · Used 4 minutes ago
  • deploy-botRead runs, publish releases · Used yesterday
  • backup-scriptRead everything · Never used

The Settings demo's access tokens. A revoked token cannot be restored, and every script that signs in with it stops, so Revoke… asks first and says both.

ConfirmDialog asks no one to type a name back. It is sized for actions whose irreversible step has a reversible alternative the wording can point at ("Archive it instead to keep its history"). An action with no such alternative, that destroys a lot, deserves more than this dialog.

A delete inside a Dialog, a Sheet or a menu follows the same table. Do it and toast with Undo while the overlay stays open: the toast comes up over it and takes the pointer there, and Undo runs without closing the overlay. From the keyboard Alt+T reaches it, and the focus comes back to the overlay afterwards.

Writing the confirmation#

  • The title is the question, with the object: "Delete 3 conversations forever?", "Revoke the token for ci-runner?".
  • The description says what cannot be undone and, if there is one, the reversible alternative. Where the title already says it all ("Discard changes?"), leave the description out: the title then stands straight over the buttons.
  • The confirm button repeats the verb: Delete, Revoke. The cancel button is Cancel.
  • The confirm button uses destructive. ConfirmDialog opens with focus on Cancel, so a stray Enter cancels.

Placement#

  • In a menu, a destructive item comes last, after a separator, with variant="destructive".
  • In a toolbar or a row, a destructive action is a ghost or destructive button away from the primary one, never the primary button itself.
  • Bulk actions say their count in the label: Delete 3 conversations.

On each platform#

Desktop & pointer#

  • Undo is also a shortcut where the app has one (Ctrl+Z or ⌘Z) for the last destructive action.
  • A row's delete button is always drawn, quiet and small, or waits in the row's ⋯ menu: never only on hover.

Touch#

  • Nothing appears only on hover: a row's delete action is always visible, or lives in the row's menu.
  • A toast sits at the screen's edge, away from the thumb. Keep it up long enough for Undo to be reached, and offer the same undo where the item was, if the app has a place for it.
  • A swipe that deletes is still followed by Undo: a swipe is easy to make by accident.

In the demos