Toast

One stack for flashes and server toasts: update in place, undo, and survive a redirect.

Put one 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.

Kinds

Update in place

Give a toast an id and update or dismiss it later. "Uploading..." becomes "Uploaded" in the same place.

Update in 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.

Undo

From a LiveComponent

Toast.send/3 works from a LiveView, a LiveComponent or any process (pass to: pid ).

From a LiveComponent
Sent 0 so far

After a redirect

put_toast/4 queues a toast on a conn or a socket and it survives the redirect, as a flash does.

put_toast, then navigate

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

  • corner is 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-bottom and --toast-offset-top .
  • A "Can't reach the server" notice appears 3 seconds after a disconnect and goes away on reconnect.
  • toast_container/1 and the old push_event(socket, "toast", ...) are deprecated; use Toast.send/3 .

Are you sure?