An undo snackbar toast built with Tailwind CSS and vanilla JavaScript. Deleting a message from the dark inbox list slides a light snackbar up from the bottom of the screen with an Undo button and a shrinking countdown bar, so an accidental delete can be reversed before it becomes final. It is the "soft delete" pattern used by mail clients, task managers and admin tables.
How it works
The root is .usb-root. It holds the inbox card with the [data-usb-list] list of li.usb-item rows, an empty state [data-usb-empty], the fixed .usb-snackbar and a visually hidden role="status" region. Each row carries its subject in data-usb-label and a [data-usb-delete] button.
A click on a delete button marks the row as pending, plays the usb-leave animation and then sets hidden on it instead of removing it. The snackbar opens through data-usb-open="true", shows the subject in [data-usb-message] and starts a timer from data-usb-timeout. The .usb-timer bar shrinks with the usb-countdown keyframes. Pressing [data-usb-undo] unhides the row with a short highlight; when the timer ends, the close button is pressed, or another row is deleted, commit() removes the row from the DOM for good. Hovering or focusing the snackbar pauses both the timer and the bar.
For the preview, the row marked data-usb-deleted starts as the pending item, so the snackbar is visible on load without a countdown.
Customization
data-usb-timeout="5000"on.usb-root: set how many milliseconds users have to undo; the countdown bar uses the same value.commit()inscript.js: add yourfetch()DELETE request there, so the server only deletes once the undo window has passed.bg-zinc-100andtext-violet-700on.usb-snackbarand[data-usb-undo]: change the snackbar surface and action color;bg-violet-600on[data-usb-timer]colors the bar.fixed inset-x-4 bottom-4 max-w-mdon.usb-snackbar: usesm:left-6 sm:right-autoto pin it bottom-left, orabsoluteto keep it inside a container.transformand thecubic-bezierin.usb-snackbarinstyle.css: adjust the slide-in distance and bounce.- Remove
data-usb-deletedfrom the Daniel Okafor row to start with a full list and a hidden snackbar.
Use cases
- Email and inbox apps: deleting a message shows a snackbar with an Undo button
- Admin tools: a countdown bar shows how long Undo stays available
- Task managers: the timer pauses on hover so users have time to restore an item
- Accessible interfaces: focus handling keeps keyboard users in control after a delete
Accessibility
Each delete button has an aria-label that names the sender. After a delete, focus moves to the next row's delete button (or to Undo when the list is empty), and after Undo it returns to the restored row. The polite role="status" region announces "Message deleted. Press Undo to restore it." and "Message restored." While closed, the snackbar uses visibility: hidden, so its buttons are skipped by Tab. Escape inside the snackbar dismisses it, the timer pauses on focus so keyboard users have time to act, and all motion stops under prefers-reduced-motion.
Usage notes
The snackbar is fixed to the viewport, so use one .usb-root per page or switch it to absolute for several demos.