HelixOverviewComponentsMapsGraphIntroductionInstallationDeriving a themeSandboxTheme builderVisual testingCortexDocsEngramBuildingTraceBuildingRecallDeclaredServicesInsightsGet in touchSource on GitHub
Essentials
Undo an action from a toastAn action a reader can take back does not need a confirmation dialog. Do the
action at once, then show a toast that offers to undo it. The reader who meant
it loses no time, and the reader who did not has a few seconds to take it back.Show the toast after the actionCall undoable() on a Toast region after the action, with what to do if the
reader undoes it:conststack=document.querySelector('helix-toast')archive(file)stack.undoable(`Archived ${file.name}`,{undo:()=>restore(file),})The message holds an Undo button and shows for 8 seconds. While it shows:Command+Z, or Control+Z on Windows and Linux, undoes the newest one, unless
focus is in a text field, which keeps the key for its own undo, or the app
handled the key first and called preventDefault().A pointer or focus in the stack pauses its timer.A screen reader hears the message and then which keys undo it.The shortcut overlay and its sheet list the key.An app with an undo of its own on those keys, such as a canvas or an editor,
sets undo-keys="" on the region. The Undo button stays, and the keys stay
the app's.Hold back what cannot be taken backWhere the action cannot be reversed once it has happened, such as deleting a
record on a server, do it when the message closes. Remove the item from the
page at once, and pass commit:row.hidden=trueconstresult=awaitstack.undoable('Deleted 3 files',{commit:()=>deleteOnServer(ids),undo:()=>(row.hidden=false),})undoable() returns a promise that settles to undone or kept.A message that never closes is kept as well: commit runs when the region
leaves the page, such as on a route change, and when the page is hidden to be
closed or reloaded. A browser can end a page without telling it, so a server
that holds a deletion back should also finish it on a timeout of its own.Keep a confirmation where an undo cannot helpActionUseArchive, move, rename, reorder, or change a settingUndo toastDelete to a trash, or delete held back until the message closesUndo toastDelete with no way back, such as emptying the trashConfirmation dialogSend, publish, invite, or payConfirmation dialogAn action that reaches another person or leaves the app cannot be taken back
from a toast, because it has already happened somewhere you do not control.
Ask first with a Dialog with alert.