Skip to content

Commit

Permalink
Merge pull request #3459 from alphagov/filter-panel-prefix
Browse files Browse the repository at this point in the history
Filter section: make a11y heading prefix configurable
  • Loading branch information
csutter authored Sep 19, 2024
2 parents 9aede0e + 213d76b commit cab421b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/views/components/_filter_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
open ||= nil
status_text ||= ""
heading_text ||= ""
visually_hidden_heading_prefix ||= ""
heading_level ||= 2
summary_aria_attributes ||= {}

Expand All @@ -16,7 +16,9 @@
<%= tag.details(**component_helper.all_attributes) do %>
<%= tag.summary class: "app-c-filter-section__summary", aria: summary_aria_attributes do %>
<%= content_tag("h#{heading_level}", class: "app-c-filter-section__summary-heading") do %>
<span class="govuk-visually-hidden">Filter by</span>
<% if visually_hidden_heading_prefix.present? %>
<span class="govuk-visually-hidden"><%= visually_hidden_heading_prefix %></span>
<% end %>
<%= heading_text %>
<% end %>
Expand Down
13 changes: 10 additions & 3 deletions app/views/components/docs/filter_section.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ accessibility_criteria: |
examples:
default:
data:
heading_text: Filter by something
heading_text: Some metadata field
block: |
<span>Filter form controls</span>
open:
data:
heading_text: Filter by something
heading_text: Some metadata field
open: true
block: |
<span>Filter form controls open by default</span>
with_visually_hidden_heading_prefix:
description: Prefix the heading text with visually hidden text for screenreaders to make it more descriptive.
data:
heading_text: Some metadata field
visually_hidden_heading_prefix: Filter by
block: |
<span>Filter form controls</span>
status_text:
data:
heading_text: Filter by something
heading_text: Some metadata field
status_text: 1 Selected
block: |
<span>Filter form controls with status text</span>
Expand Down
8 changes: 7 additions & 1 deletion spec/components/filter_section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ def render_component(locals)
assert_select ".app-c-filter-section[open=open]"
end

it "set section heading text with hidden context for accessibility" do
it "sets the heading text" do
render_component({ heading_text: "section heading" })

assert_select ".app-c-filter-section__summary-heading", text: "section heading"
end

it "adds the visually hidden heading prefix if given" do
render_component({ heading_text: "section heading", visually_hidden_heading_prefix: "Filter by" })

assert_select ".app-c-filter-section__summary-heading", include: "section heading"
assert_select ".app-c-filter-section__summary-heading .govuk-visually-hidden", text: "Filter by"
end
Expand Down

0 comments on commit cab421b

Please sign in to comment.