Skip to content

Commit 4f60d42

Browse files
committed
Fix pivot facet accessibility by using tree, treeitem aria roles. Fixes #3559.
- Sets a pivot facet's root ul to role="tree", leaves regular facets without role - Restores the pivot facet li role="treeitem" that was removed in #3359
1 parent 61c199f commit 4f60d42

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

app/components/blacklight/facet_item_pivot_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def call
3232

3333
id = "h-#{self.class.mint_id}" if @collapsing && has_items?
3434

35-
content_tag @wrapping_element, class: 'treeitem' do
35+
content_tag @wrapping_element, class: 'treeitem', role: 'treeitem' do
3636
concat(content_tag('span', class: "d-flex flex-row align-items-center") do
3737
concat facet_toggle_button(id) if has_items? && @collapsing
3838
concat content_tag('span', render(facet), class: "facet-values d-flex flex-row flex-grow-1 #{'facet-leaf-node' if has_items? && @collapsing}", id: id && "#{id}_label")

app/components/blacklight/facets/list_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<% end %>
55
<% component.with_body do %>
66
<%= render(Blacklight::Facets::InclusiveConstraintComponent.new(facet_field: @facet_field)) %>
7-
<ul class="facet-values list-unstyled">
7+
<%= content_tag :ul, class: 'facet-values list-unstyled', role: @role do %>
88
<%= render facet_items %>
9-
</ul>
9+
<% end %>
1010
<% end %>
1111
<% end %>

app/components/blacklight/facets/list_component.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
module Blacklight
44
module Facets
55
class ListComponent < Blacklight::Component
6-
def initialize(facet_field:, layout: nil)
6+
def initialize(facet_field:, role: nil, layout: nil)
77
@facet_field = facet_field
8+
@role = role
89
@layout = layout == false ? Blacklight::Facets::NoLayoutComponent : Blacklight::Facets::FieldComponent
910
end
1011

11-
attr_accessor :layout
12+
attr_accessor :layout, :role
1213

1314
def facet_items(wrapping_element: :li, **item_args)
1415
facet_item_component_class.with_collection(facet_item_presenters, wrapping_element: wrapping_element, **item_args)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
class PivotListComponent < Blacklight::Facets::ListComponent
6+
def initialize(facet_field:, role: 'tree', layout: nil)
7+
super
8+
end
9+
end
10+
end
11+
end

lib/blacklight/configuration/facet_field.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def normalize! blacklight_config = nil
9595
def normalize_pivot_config!
9696
self.item_presenter ||= Blacklight::FacetItemPivotPresenter
9797
self.item_component ||= Blacklight::FacetItemPivotComponent
98+
self.component ||= Blacklight::Facets::PivotListComponent
9899
self.filter_class ||= Blacklight::SearchState::PivotFilterField
99100
self.filter_query_builder ||= Blacklight::SearchState::PivotFilterField::QueryBuilder
100101
end

spec/components/blacklight/facets/list_component_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
expect(page).to have_css 'li', count: 2
4343
end
4444

45+
it 'does not add a role attribute by default' do
46+
expect(page).to have_css 'ul.facet-values'
47+
expect(page).to have_no_css 'ul.facet-values[role]'
48+
end
49+
4550
context 'with an active facet' do
4651
let(:facet_field) do
4752
instance_double(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Blacklight::Facets::PivotListComponent, type: :component do
6+
before do
7+
render_inline(described_class.new(facet_field: facet_field))
8+
end
9+
10+
let(:facet_field) do
11+
instance_double(
12+
Blacklight::FacetFieldPresenter,
13+
paginator: paginator,
14+
facet_field: facet_config,
15+
key: 'pivot_field',
16+
label: 'Pivot Field',
17+
active?: false,
18+
collapsed?: false,
19+
modal_path: nil,
20+
values: []
21+
)
22+
end
23+
24+
let(:facet_config) do
25+
Blacklight::Configuration::NullField.new(
26+
key: 'pivot_field',
27+
item_component: Blacklight::FacetItemPivotComponent,
28+
item_presenter: Blacklight::FacetItemPivotPresenter,
29+
pivot: %w[field_a field_b]
30+
)
31+
end
32+
33+
let(:paginator) do
34+
instance_double(Blacklight::FacetPaginator, items: [
35+
double(value: 'x', hits: 10),
36+
double(value: 'y', hits: 33)
37+
])
38+
end
39+
40+
it 'renders the facet items with role="tree"' do
41+
expect(page).to have_css 'ul.facet-values[role="tree"]'
42+
end
43+
end

0 commit comments

Comments
 (0)