Skip to content

Commit

Permalink
Remove redundant aria-labelledby; the title is sufficient on its own
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 18, 2020
1 parent 1feabd2 commit 6de0f28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
7 changes: 1 addition & 6 deletions app/models/blacklight/icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ def initialize(icon_name, classes: '', aria_hidden: false, label: true, role: 'i
def svg
svg = ng_xml.at_xpath('svg')
svg['role'] = role
svg['aria-labelledby'] = unique_id if label
svg.prepend_child("<title id='#{unique_id}'>#{icon_label}</title>") if label
svg.prepend_child("<title>#{icon_label}</title>") if label
ng_xml.to_xml
end

def icon_label
I18n.translate("blacklight.icon.#{icon_name_context}", default: "#{icon_name} icon")
end

def unique_id
@unique_id ||= "bl-icon-#{icon_name_context}-#{SecureRandom.hex(8)}"
end

##
# @return [Hash]
def options
Expand Down
12 changes: 2 additions & 10 deletions spec/models/blacklight/icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
end
it 'adds title' do
expect(Capybara.string(subject.svg))
.to have_css 'title[id^="bl-icon-search-"]', text: 'search icon'
end
it 'adds aria-labelledby' do
expect(Capybara.string(subject.svg))
.to have_css 'svg[aria-labelledby^="bl-icon-search-"]'
.to have_css 'title', text: 'search icon'
end
context 'when label is false' do
subject { described_class.new(:search, classes: 'awesome', aria_hidden: true, label: false) }
Expand All @@ -30,18 +26,14 @@
expect(Capybara.string(subject.svg))
.not_to have_css 'title', text: 'search icon'
end
it 'does not add aria-labelledby' do
expect(Capybara.string(subject.svg))
.not_to have_css 'svg[aria-labelledby^="bl-icon-search-"]'
end
end

context ' with a label context' do
subject { described_class.new(:search, classes: 'awesome', aria_hidden: true, additional_options: { label_context: 'foo' }) }

it 'adds title' do
expect(Capybara.string(subject.svg))
.to have_css 'title[id^="bl-icon-search_foo-"]', text: 'search icon'
.to have_css 'title', text: 'search icon'
end
end
end
Expand Down

0 comments on commit 6de0f28

Please sign in to comment.