Announce Toasts Politely

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Show short notifications ("toasts") that screen readers announce. An "Archive" button adds a toast reading "Message archived", and a "Star" button one reading "Message starred". Put the toasts inside one element with role="status" that is always on the page, even while it's empty: screen readers only announce changes to a live region that was already there. Each toast has its own dismiss button, named "Dismiss" followed by its message (for example "Dismiss Message archived"; an aria-label is fine), that removes just that toast. Each toast also removes itself duration milliseconds after it appeared (a prop, default 5000), on its own timer: adding or removing other toasts mustn't restart it. The checks use durations under half a second.

Your code must pass

  • The status region is on the page, empty, before any toast
  • Archive and Star add their toasts inside the status region
  • Dismiss removes just that toast
  • Each toast disappears after duration milliseconds
  • Each toast keeps its own timer