diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a2f9c6029..0ca885593 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/layouts/_flash_messages.html.haml b/app/views/layouts/_flash_messages.html.haml index b0a3e5d72..55dd13ac8 100644 --- a/app/views/layouts/_flash_messages.html.haml +++ b/app/views/layouts/_flash_messages.html.haml @@ -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) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 44416c4b8..6b70a8097 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -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