From 9ec58d8a67c611a5544c0994a8ef9f350a94d2db Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Wed, 12 Apr 2017 19:55:14 -0500 Subject: [PATCH 1/4] Add aria to icon --- app/helpers/icons_helper.rb | 5 +++++ changelogs/unreleased/add-aria-to-icon.yml | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/unreleased/add-aria-to-icon.yml diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index ab3ef454e1c..ef260cff182 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -7,6 +7,11 @@ module IconsHelper # font-awesome-rails gem, but should we ever use a different icon pack in the # future we won't have to change hundreds of method calls. def icon(names, options = {}) + if !options['aria-hidden'] and !options['aria-label'] + # Add `aria-hidden` if there are no aria's set + options['aria-hidden'] = true + end + options.include?(:base) ? fa_stacked_icon(names, options) : fa_icon(names, options) end diff --git a/changelogs/unreleased/add-aria-to-icon.yml b/changelogs/unreleased/add-aria-to-icon.yml new file mode 100644 index 00000000000..b1449bf16a6 --- /dev/null +++ b/changelogs/unreleased/add-aria-to-icon.yml @@ -0,0 +1,4 @@ +--- +title: Update icon() to automatically include aria-hidden if aria is not found +merge_request: +author: From 7f66e8ad17141cbe8a1b87adce665f49f94a4aa4 Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Tue, 18 Apr 2017 10:27:10 -0500 Subject: [PATCH 2/4] Add tests --- app/helpers/icons_helper.rb | 2 +- spec/helpers/icons_helper_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index ef260cff182..55fa81e95ef 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -7,7 +7,7 @@ module IconsHelper # font-awesome-rails gem, but should we ever use a different icon pack in the # future we won't have to change hundreds of method calls. def icon(names, options = {}) - if !options['aria-hidden'] and !options['aria-label'] + if (options.keys & %w[aria-hidden aria-label]).empty? # Add `aria-hidden` if there are no aria's set options['aria-hidden'] = true end diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb index c052981fe73..c3f78d3d61f 100644 --- a/spec/helpers/icons_helper_spec.rb +++ b/spec/helpers/icons_helper_spec.rb @@ -1,6 +1,19 @@ require 'spec_helper' describe IconsHelper do + describe 'icon' do + it 'returns aria-hidden by default' do + star = icon('star') + expect(star['aria-hidden']).to eq 'aria-hidden' + end + + it 'does not return aria-hidden if aria-label is set' do + up = icon('up', 'aria-label' => 'up') + expect(up['aria-hidden']).to eq nil + expect(up['aria-label']).to eq 'aria-label' + end + end + describe 'file_type_icon_class' do it 'returns folder class' do expect(file_type_icon_class('folder', 0, 'folder_name')).to eq 'folder' From ffe4e5c74dc3913f3c0abe6f5d410033d2b9e5de Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Mon, 24 Apr 2017 10:14:34 -0400 Subject: [PATCH 3/4] Improve specs --- spec/helpers/icons_helper_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb index c3f78d3d61f..91c8faea7fd 100644 --- a/spec/helpers/icons_helper_spec.rb +++ b/spec/helpers/icons_helper_spec.rb @@ -4,12 +4,14 @@ describe IconsHelper do describe 'icon' do it 'returns aria-hidden by default' do star = icon('star') + expect(star['aria-hidden']).to eq 'aria-hidden' end it 'does not return aria-hidden if aria-label is set' do up = icon('up', 'aria-label' => 'up') - expect(up['aria-hidden']).to eq nil + + expect(up['aria-hidden']).to be_nil expect(up['aria-label']).to eq 'aria-label' end end From f0a164a6d58fe8fe1711a7afbd698a5c2b546a1e Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Mon, 24 Apr 2017 14:21:55 -0400 Subject: [PATCH 4/4] Update changelog --- changelogs/unreleased/add-aria-to-icon.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/unreleased/add-aria-to-icon.yml b/changelogs/unreleased/add-aria-to-icon.yml index b1449bf16a6..fd6a25784c6 100644 --- a/changelogs/unreleased/add-aria-to-icon.yml +++ b/changelogs/unreleased/add-aria-to-icon.yml @@ -1,4 +1,4 @@ --- -title: Update icon() to automatically include aria-hidden if aria is not found +title: Fixes an issue preventing screen readers from reading some icons merge_request: author: