Improve status message delivery to assistive technologies
This commit is contained in:
parent
4e64eb1af5
commit
fd049f6025
3 changed files with 22 additions and 23 deletions
|
@ -36,16 +36,9 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def flash_class(level, sticky: false, fixed: false)
|
def flash_class(sticky: false, fixed: false)
|
||||||
class_names = []
|
class_names = []
|
||||||
|
|
||||||
case level
|
|
||||||
when 'notice'
|
|
||||||
class_names << 'alert-success'
|
|
||||||
when 'alert', 'error'
|
|
||||||
class_names << 'alert-danger'
|
|
||||||
end
|
|
||||||
|
|
||||||
if sticky
|
if sticky
|
||||||
class_names << 'sticky'
|
class_names << 'sticky'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
#flash_messages{ aria: { live: 'assertive' } }
|
#flash_messages
|
||||||
- if flash.any?
|
#flash_message.center
|
||||||
#flash_message.center
|
- if flash.any?
|
||||||
- flash.each do |key, value|
|
- flash.each do |key, value|
|
||||||
- sticky = defined?(sticky) ? sticky : false
|
- sticky = defined?(sticky) ? sticky : false
|
||||||
- fixed = defined?(fixed) ? fixed : false
|
- fixed = defined?(fixed) ? fixed : false
|
||||||
- if value.class == Array
|
- if flash_role(key) == 'status'
|
||||||
.alert{ class: flash_class(key, sticky: sticky, fixed: fixed), role: flash_role(key) }
|
.alert.alert-success{ role: 'status', class: flash_class(sticky: sticky, fixed: fixed), tabindex: '-1', data: { controller: 'autofocus' } }
|
||||||
- value.each do |message|
|
- if value.class == Array
|
||||||
= sanitize_with_link(message)
|
- value.each do |message|
|
||||||
%br
|
= sanitize_with_link(message)
|
||||||
- elsif value.present?
|
%br
|
||||||
.alert{ class: flash_class(key, sticky: sticky, fixed: fixed), role: flash_role(key) }
|
- elsif value.present?
|
||||||
= sanitize_with_link(value)
|
= 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)
|
||||||
|
|
|
@ -71,10 +71,8 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#flash_class" do
|
describe "#flash_class" do
|
||||||
it { expect(flash_class('notice')).to eq 'alert-success' }
|
it { expect(flash_class(sticky: true)).to eq 'sticky' }
|
||||||
it { expect(flash_class('alert', sticky: true, fixed: true)).to eq 'alert-danger sticky alert-fixed' }
|
it { expect(flash_class(fixed: true)).to eq 'alert-fixed' }
|
||||||
it { expect(flash_class('error')).to eq 'alert-danger' }
|
|
||||||
it { expect(flash_class('unknown-level')).to eq '' }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#try_format_date" do
|
describe "#try_format_date" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue