Skip to content

Commit

Permalink
Add additional accessible text to linked faceted searches
Browse files Browse the repository at this point in the history
This updates the LinkToFacet rendering step to add an additional
visually hidden element when creating a link to a faceted search
that indicates the facet that will be used in the search.

This helps give additional context to screen reader users when
link_to_facet is used, especially when the page may include
links that go to searches for the same value in different fields.

Fixes #3427
  • Loading branch information
thatbudakguy committed Oct 31, 2024
1 parent 344df8a commit 79d0a73
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/presenters/blacklight/rendering/link_to_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ def link_field
end

def link(field, v)
context.link_to v, search_path(field, v)
context.link_to search_path(field, v) do
context.tag.span(v) +
context.tag.span(search_description, class: 'visually-hidden')
end
end

def search_path(field, v)
context.search_action_path(facet_params(field, v))
end

# Accessible description for the link, indicating it will do a faceted search
def search_description
context.t 'blacklight.search.facets.faceted_search', field_label: config.display_label
end

def facet_params(field, item)
context.search_state.reset.filter(field).add(item).params
end
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ar:
all: الكل
clear: إزالة معايير البحث
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: إخفاء الأوجه
open: عرض الأوجه
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ de:
all: Alle
clear: Löschen
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Facetten ausblenden
open: Facetten zeigen
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ en:
label: "Filter %{field_label}"
placeholder: Filter...
title: Limit your search
faceted_search: "%{field_label} search"
filters:
label: "%{label}:"
remove:
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ es:
all: Todos
clear: Borrar
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Ocultar facetas
open: Mostrar facetas
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fr:
all: Tout
clear: Effacer
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Masquer les facettes
open: Afficher les facettes
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ hu:
all: Minden
clear: Szűrőfeltétel eltávolítása
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Fazetek elrejtése
open: Szempontok megjelenítése
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ it:
all: Ogni
clear: Cancella
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Nascondi sfaccettature
open: Mostra sfaccettature
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ nl:
all: Al
clear: Filters legen
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Verberg facetten
open: Toon facetten
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pt-BR:
all: Todo
clear: Limpar
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Ocultar facetas
open: Mostrar facetas
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.sq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ sq:
all: Gjithë
clear: Fshij filterin
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: Fshih aspektet
open: Trego aspektet
Expand Down
1 change: 1 addition & 0 deletions config/locales/blacklight.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ zh:
all:
clear: 清除搜索条件
count: "%{number}"
faceted_search: "%{field_label} search"
group:
close: 隐藏方面
open: 显示方面
Expand Down
4 changes: 2 additions & 2 deletions spec/presenters/blacklight/field_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def render
context 'when field has link_to_facet with true' do
before do
allow(request_context).to receive(:search_action_path).with({ 'f' => { 'link_to_facet_true' => ['x'] } }).and_return('/foo')
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
allow(request_context).to receive(:link_to).with('/foo').and_return('bar')
end

let(:field_name) { 'link_to_facet_true' }
Expand All @@ -94,7 +94,7 @@ def render
context 'when field has link_to_facet with a field name' do
before do
allow(request_context).to receive(:search_action_path).with({ 'f' => { 'some_field' => ['x'] } }).and_return('/foo')
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
allow(request_context).to receive(:link_to).with('/foo').and_return('bar')
end

let(:field_name) { 'link_to_facet_named' }
Expand Down
37 changes: 37 additions & 0 deletions spec/presenters/blacklight/rendering/link_to_facet_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Rendering::LinkToFacet do
include Capybara::RSpecMatchers
include Rails.application.routes.url_helpers

let(:field_config) { Blacklight::Configuration::Field.new(link_to_facet: true, key: 'key', label: 'label') }
let(:document) { instance_double(SolrDocument) }
let(:query_params) { { controller: 'catalog', action: 'show' } }
let(:config) { Blacklight::Configuration.new }
let(:search_state) { Blacklight::SearchState.new(query_params, config) }
let(:context) { double(search_state: search_state) }
let(:pipeline) { Blacklight::Rendering::Pipeline.new(values, field_config, document, context, [described_class], {}) }

before do
allow(context).to receive_messages(
search_action_path: double,
link_to: double,
tag: double(span: nil),
t: 'label search'
)
end

describe '#render' do
let(:values) { %w[a] }

before { pipeline.render }

it 'renders the value' do
expect(context.tag).to have_received(:span).with('a')
end

it 'renders the accessible description' do
expect(context.tag).to have_received(:span).with('label search', class: 'visually-hidden')
end
end
end

0 comments on commit 79d0a73

Please sign in to comment.