Skip to content

Commit

Permalink
Add an aria label to the button.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeck committed Dec 13, 2019
1 parent 782b0c4 commit e8e36e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions app/helpers/blacklight/hierarchy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ def render_facet_hierarchy_item(field_name, data, key)
subset = data.reject { |k, _v| !k.is_a?(String) }

li_class = subset.empty? ? 'h-leaf' : 'h-node'
id = SecureRandom.uuid
ul = ''
li = ''
li << facet_toggle_link if subset.any?
li << facet_toggle_button(field_name, id) if subset.any?
li << if item.nil?
key
elsif facet_in_params?(field_name, item.qvalue)
render_selected_qfacet_value(field_name, item)
else
render_qfacet_value(field_name, item)
render_qfacet_value(field_name, item, id: id)
end

unless subset.empty?
Expand Down Expand Up @@ -43,7 +44,8 @@ def render_hierarchy(bl_facet_field, delim = '_')
end

def render_qfacet_value(facet_solr_field, item, options = {})
(link_to_unless(options[:suppress_link], item.value, path_for_facet(facet_solr_field, item.qvalue), class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe
id = options.delete(:id)
(link_to_unless(options[:suppress_link], item.value, path_for_facet(facet_solr_field, item.qvalue), id: id, class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe
end

# Standard display of a SELECTED facet value, no link, special span with class, and 'remove' button.
Expand Down Expand Up @@ -102,11 +104,20 @@ def facet_tree(hkey)
@facet_tree[hkey]
end

def facet_toggle_link
def facet_toggle_button(field_name, described_by)
aria_label = I18n.t(
"blacklight.hierarchy.#{field_name}_toggle_aria_label",
default: :'blacklight.hierarchy.toggle_aria_label'
)
<<-HTML
<button class="toggle-handle" aria-expanded="false">
<span class="closed">#{Blacklight::Hierarchy::Engine.config.closed_icon}</span>
<span class="opened">#{Blacklight::Hierarchy::Engine.config.opened_icon}</span>
<button
aria-expanded="false"
aria-label="#{aria_label}"
aria-describedby="#{described_by}"
class="toggle-handle"
>
<span aria-hidden="true" class="closed">#{Blacklight::Hierarchy::Engine.config.closed_icon}</span>
<span aria-hidden="true" class="opened">#{Blacklight::Hierarchy::Engine.config.opened_icon}</span>
</button>
HTML
end
Expand Down
4 changes: 4 additions & 0 deletions config/locales/blacklight-hierarchy.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
blacklight:
hierarchy:
toggle_aria_label: Toggle subgroup

0 comments on commit e8e36e4

Please sign in to comment.