Improve status message delivery to assistive technologies

This commit is contained in:
Corinne Durrmeyer 2024-10-18 16:45:40 +02:00
parent 4e64eb1af5
commit fd049f6025
No known key found for this signature in database
GPG key ID: DDC049DDA35585B6
3 changed files with 22 additions and 23 deletions

View file

@ -36,16 +36,9 @@ module ApplicationHelper
end
end
def flash_class(level, sticky: false, fixed: false)
def flash_class(sticky: false, fixed: false)
class_names = []
case level
when 'notice'
class_names << 'alert-success'
when 'alert', 'error'
class_names << 'alert-danger'
end
if sticky
class_names << 'sticky'
end

View file

@ -1,14 +1,22 @@
#flash_messages{ aria: { live: 'assertive' } }
- if flash.any?
#flash_message.center
#flash_messages
#flash_message.center
- if flash.any?
- flash.each do |key, value|
- sticky = defined?(sticky) ? sticky : false
- fixed = defined?(fixed) ? fixed : false
- if value.class == Array
.alert{ class: flash_class(key, sticky: sticky, fixed: fixed), role: flash_role(key) }
- value.each do |message|
= sanitize_with_link(message)
%br
- elsif value.present?
.alert{ class: flash_class(key, sticky: sticky, fixed: fixed), role: flash_role(key) }
= sanitize_with_link(value)
- if flash_role(key) == 'status'
.alert.alert-success{ role: 'status', class: flash_class(sticky: sticky, fixed: fixed), tabindex: '-1', data: { controller: 'autofocus' } }
- if value.class == Array
- value.each do |message|
= sanitize_with_link(message)
%br
- elsif value.present?
= sanitize_with_link(value)
- elsif flash_role(key) == 'alert'
.alert.alert-danger{ role: 'alert', class: flash_class(sticky: sticky, fixed: fixed), tabindex: '-1', data: { controller: 'autofocus' } }
- if value.class == Array
- value.each do |message|
= sanitize_with_link(message)
%br
- elsif value.present?
= sanitize_with_link(value)

View file

@ -71,10 +71,8 @@ describe ApplicationHelper do
end
describe "#flash_class" do
it { expect(flash_class('notice')).to eq 'alert-success' }
it { expect(flash_class('alert', sticky: true, fixed: true)).to eq 'alert-danger sticky alert-fixed' }
it { expect(flash_class('error')).to eq 'alert-danger' }
it { expect(flash_class('unknown-level')).to eq '' }
it { expect(flash_class(sticky: true)).to eq 'sticky' }
it { expect(flash_class(fixed: true)).to eq 'alert-fixed' }
end
describe "#try_format_date" do