# Undo and destructive actions

Decide between acting at once with Undo and asking first, and shape both.

* Kind: pattern
* Page: https://design.werklist.com/patterns/undo
* Version: 2.1.2

## When to use it

* Any change that can be restored: archiving a candidate, moving a candidate to another stage, removing a candidate from a shortlist
* A confirmation before a rare action nothing can restore, before an irreversible change for other people, or before losing typed entries

## When not to use it

* A confirmation before an action that can be undone
* A Do not ask again checkbox
* Typing the name of the object to confirm
* A button that has to be pressed twice to confirm

## Rules

* Act at once and offer Undo for any change that can be restored.
* Ask first only for a rare action nothing can restore, an irreversible change for other people, or closing a form with unsaved entries.
* A selection follows the same rule. Archiving a selection asks nothing and Undo brings every row back. Deleting a selection permanently asks in place on the selection bar.
* One undo toast at a time. A second undoable action carries out the first and takes its place.
* Undo stays open for 5 seconds.
* The countdown pauses while the pointer rests on the toast or focus is inside it.
* When the time runs out, the action is carried out and the item can still be found where it went.
* The Undo button is at least 24 px high, 44 px on touch screens. On a wide screen the toast sits at the bottom center, 24 px above the window edge.
* A screen reader announces the toast once, when it appears. The countdown is not announced.
* Ask in the small confirmation dialog. The title is a question that names the object, and the body says what is lost and for whom.
* The buttons are Cancel and the verb of the title. The verb takes the danger style when it deletes.
* Focus starts on Cancel, Escape answers Cancel, and a press on the dimmed page does nothing.
* If a change cannot be saved when the time runs out, the rows come back and a toast says so.

## Content

* Toast: the past tense, with the object and its count: Candidate archived, 12 candidates archived. The button reads Undo, or a more exact word such as Restore.
* Confirmation titles: Delete this candidate permanently? Close this job and notify 38 applicants?
* Confirmation body: Every applicant for Welder in Split receives an email that the role is filled. An email that has gone out cannot be taken back.
* Failure: Some candidates could not be changed.

## Tokens

* --space-6
* --layer-toast
* --glass-fill-raised
* --elevation-3
* --brand-ink
* --error-ink
