Merge branch 'add-aria-to-icon' into 'master'

Add aria to icon

See merge request !10670
This commit is contained in:
Jacob Schatz 2017-04-24 19:55:46 +00:00
commit 22c88c675d
3 changed files with 24 additions and 0 deletions

View File

@ -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.keys & %w[aria-hidden aria-label]).empty?
# 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

View File

@ -0,0 +1,4 @@
---
title: Fixes an issue preventing screen readers from reading some icons
merge_request:
author:

View File

@ -1,6 +1,21 @@
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 be_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'