Skip to content

Commit 7391a74

Browse files
authored
Merge pull request #2126 from labradford/arclight-616-screenreader-duplicate-search
ability to add aria-hidden to blacklight icon
2 parents d9aeeae + 8b13826 commit 7391a74

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

app/models/blacklight/icon.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Icon
77
# @param [String, Symbol] icon_name
88
# @param [Hash] options
99
# @param [String] classes additional classes separated by a string
10-
def initialize(icon_name, classes: '')
10+
def initialize(icon_name, classes: '', aria_hidden: false)
1111
@icon_name = icon_name
1212
@classes = classes
13+
@aria_hidden = aria_hidden
1314
end
1415

1516
##
@@ -23,7 +24,8 @@ def svg
2324
# @return [Hash]
2425
def options
2526
{
26-
class: classes
27+
class: classes,
28+
"aria-hidden": (true if @aria_hidden)
2729
}
2830
end
2931

app/views/catalog/_search_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<span class="input-group-append">
2121
<button type="submit" class="btn btn-primary search-btn" id="search">
2222
<span class="submit-search-text"><%= t('blacklight.search.form.submit') %></span>
23-
<%= blacklight_icon :search %>
23+
<%= blacklight_icon :search, aria_hidden: true %>
2424
</button>
2525
</span>
2626
</div>

spec/models/blacklight/icon_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Blacklight::Icon do
4-
subject { described_class.new(:search, classes: 'awesome') }
4+
subject { described_class.new(:search, classes: 'awesome', aria_hidden: true) }
55

66
describe '#svg' do
77
it 'returns a string' do
@@ -17,6 +17,20 @@
1717
it 'applies options classes and default class' do
1818
expect(subject.options[:class]).to eq 'blacklight-icons awesome'
1919
end
20+
it 'applies options aria-hidden=true' do
21+
expect(subject.options[:'aria-hidden']).to be true
22+
end
23+
context 'no options provided' do
24+
subject { described_class.new(:view) }
25+
26+
it 'applies default class with no options' do
27+
expect(subject.options[:class]).to eq 'blacklight-icons'
28+
end
29+
30+
it 'has no aria-hidden attribute with no options' do
31+
expect(subject.options[:'aria-hidden']).to be nil
32+
end
33+
end
2034
end
2135

2236
describe '#path' do

0 commit comments

Comments
 (0)