Feedback
Toast, inline message or dialog: where a result is said depends on whether people have to do something about it.
Say a result where people will act on it. A toast for something done that needs nothing more, an inline message beside whatever needs fixing, and a dialog only when nothing may go on until it is answered.
Copy link, from a Mail conversation's menu, succeeds and asks for nothing, so a toast says so and goes away. Press Save profile: the email from the Settings demo's profile form is missing its domain, which is said under the field and stays until the field is fixed. The pull request's checks failed to refresh, so the warning sits above the list it could not update, with the one control that can fix it.
Do and don't#
Enter an email address, like alice@example.com.
Put a validation error under its field, mark the field aria-invalid, and point
aria-describedby at the message.
Send a validation error as a toast: it disappears before the field is fixed, and never says which field.
Toast "3 conversations archived" with an Undo action after a bulk change that can be reversed.
Open a dialog to say that something worked. A dialog stops everything; success should not.
Which one#
| What happened | Needs people to | Use |
|---|---|---|
| An action finished as expected | Nothing; maybe undo it | toast(), toast.success(), with an action to undo |
| A control shows its own result where it was pressed | Nothing | No toast: CopyButton turns into a check; writeClipboard toasts only a failure |
| A copy came too late for the press that asked for it | Press once more | The copy offer: offerCopy, which writeClipboard and copyToClipboard raise themselves |
| Something finished in the background, out of view | Know, maybe open it | toast() with an action that opens it |
| A field or a form is wrong | Fix that field | An inline message under the field |
| A surface failed to load and has nothing to show | Retry | LoadFailure in its place |
| A refresh failed but older data is still shown | Know the data is stale, retry | RefreshFailure above the data |
| An action failed and the work is not saved | Decide what to do with it | toast.error() with a retry, or inline if the place is on screen |
| A question waits in the flow of the page, or a run there ended | Answer it, or see how it ended | A Frame with an intent, its lid saying the status, see Surfaces |
| Nothing may continue until a question is answered | Choose | Dialog, see Overlays |
Each button ends in a toast, in the demos' words. Archive can be undone from it. Re-run failed jobs finishes out of view, and its error toast opens the run.
Mail's list failed to load and has nothing to show, so LoadFailure takes its place until
Retry brings the conversations.
A message that stays has to be removable by fixing its cause, not by a close button; one that leaves by itself must not carry the only copy of something people need to read.
A control that shows its own result needs no toast as well.
Press Copy link: a CopyButton turns its icon into a check for a moment, and says "Link
copied" to a screen reader. The eyes are already on the button, and a toast in the corner would
only pull them away. Its failure still toasts, since the button cannot say why it failed.
- Copy from a button on screen with
CopyButton: a code block's Copy, a new token's Copy token, an install line's icon. Alone, the icon is named byaria-label, which its tooltip shows; give it words where the icon would not say what is copied. - Copy from a menu or a shortcut with
copyToClipboard, which toasts the success: nothing on screen changes, and the menu is gone. ACopyButtonthat a toolbar moves into its⋯menu toasts there for the same reason. - A control of another kind that answers itself copies with
writeClipboardfrom@orz/ui/lib/clipboard, which toasts only a failure. A component that reports the copy to its caller, asHexView'sonCopydoes, copies withwriteClipboardQuietly, which says nothing. - Copy in the press itself. Text still on its way, such as bytes being read, goes to any of these as a promise, handed over inside the press. A page served over plain http from another machine has no Clipboard API, and the browser's copy command these fall back to works only for a moment after the press, about a second in WebKit.
- A copy whose text came too late for its press is offered instead of failing: a toast, "Ready to
copy", whose Copy button makes the copy in a press of its own.
writeClipboardandcopyToClipboardoffer it themselves. A component that reports the copy callsofferCopywhenwriteClipboardQuietlyanswers"needs-press", and reports the offer's outcome; one closed unpressed was the reader's choice and reports nothing.
Writing the message#
- Say what happened in the past tense, naming the thing: "Profile saved", "Couldn't load the conversations". Do not open with "Success!" or "Error:"; the icon already says which.
- An error says what failed and, when it is known, the server's own words:
LoadFailureandRefreshFailuretake them asdetail, which stays out of the sentence. - A message for one item names the item; a message for several counts them.
On each platform#
Desktop & pointer#
- Toasts stack in a corner, out of the way of the work. Hovering one pauses its timer, so it can be read and its action taken.
- A toast shows over every overlay and takes the pointer there too: pressing it, or its action, closes nothing beneath it.
- A toast's action is reachable from the keyboard. Alt+T moves the focus to the toasts, from inside an open Dialog, Sheet, Popover or menu as well, and Tab past them, Escape or the action itself takes it back where it was. Still, anything that matters is also reachable where it happened, since a toast may be gone before focus reaches it.
Touch#
- A toast covers part of a small screen. Keep it to one line, and swipe it away to dismiss.
- An inline error must stay visible above the on-screen keyboard: put it directly under the field, not at the top of the form.
In the demos
- ReleasesEach change says what happened to which release in a toast, Promoting web v5.11.1 to staging or Rolled back 2 releases, with Undo in it.
- SettingsSave the profile or revoke a token for a toast that names what happened. A wrong email is said under its field instead, where it can be fixed.
- AdminEach change names what happened in a toast, Changed bob's role to Member or Revoked the invitation to peggy@example.com. A wrong address in Invite people… is said under the field instead.
- TasksClose, reopen, create or delete a task, and a toast names the task it was done to. New task with no title says so under the field.
- MailArchive, delete, mark or send a message, and a toast says so, with Undo. Press Refresh: the first check fails, and says so above the list it kept, with Retry.
- Pull requestPress Re-run failed jobs and move to Files changed: the run ends in a toast, and its Details leads back to the log.
- Config editorSave a file for a toast that names it. A syntax error is said under the editor, where it can be fixed, and pressing it moves the caret to the error.
- Binary inspectorPaste more bytes than fit, or text that is not hex: a toast says what was pasted and what was refused. Revert ends in one that names the file.