Toast
One stack for flashes and server toasts: update in place, undo, and survive a redirect.
toast_group
in the layout. It shows Phoenix flashes and toasts sent from the server. At most three are visible; older ones fold into "+n more".
Kinds
info
and
success
leave after 5 seconds,
warning
after 8, and
error
stays until dismissed. Every toast shows its kind as a word (for screen readers) and an icon. The timer pauses on hover and focus.
Update in place
Give a toast an
id
and update or dismiss it later. "Uploading..." becomes "Uploaded" in the same place.
Undo
Reversible actions happen at once and offer Undo. Only the irreversible ones ask first (see Confirm).
A toast with an action stays until you act; an explicit
duration
adds a countdown line.
From a LiveComponent
Toast.send/3
works from a LiveView, a LiveComponent or any process (pass
to: pid
).
After a redirect
put_toast/4
queues a toast on a conn or a socket and it survives the redirect, as a flash does.
Flash messages
put_flash/3
still works and shows in the same stack.
# layout
<.toast_group flash={@flash} live />
# LiveView
{:noreply, put_flash(socket, :info, "Operation completed!")}
Notes
-
corneris one of six positions (bottom right by default); on phones the group is full width at the bottom. -
Keep toasts clear of your own bars with
--toast-offset-bottomand--toast-offset-top. - A "Can't reach the server" notice appears 3 seconds after a disconnect and goes away on reconnect.
-
toast_container/1and the oldpush_event(socket, "toast", ...)are deprecated; useToast.send/3.