Make flash messages accessible to screen readers

PHOTO EMBED

Fri Jun 17 2022 09:16:41 GMT+0000 (UTC)

Saved by @metamoni #ruby #rubyonrails

# original code
<% if flash.any? %>
  <% flash.each do |type, msg| %>
    <p class="alert alert-<%= type %>">
      <%= msg %>
    </p>
  <% end %>
<% end %>

# with aria-live
<% if flash.any? %>
  <% flash.each do |type, msg| %>
    <p class="alert alert-<%= type %>" aria-live="polite">
      <%= msg %>
    </p>
  <% end %>
<% end %>
content_copyCOPY