diff --git a/app/components/govuk_component/summary_list_component/action_component.rb b/app/components/govuk_component/summary_list_component/action_component.rb index 3065e62b..1716ab3f 100644 --- a/app/components/govuk_component/summary_list_component/action_component.rb +++ b/app/components/govuk_component/summary_list_component/action_component.rb @@ -19,8 +19,10 @@ def render? end def call + space = config.summary_list_action_visually_hidden_space ? nil : " " + link_to(href, **html_attributes) do - safe_join([action_text, visually_hidden_span].compact, " ") + safe_join([action_text, visually_hidden_span].compact, space) end end @@ -37,6 +39,8 @@ def action_text end def visually_hidden_span - tag.span(visually_hidden_text, class: "govuk-visually-hidden") if visually_hidden_text.present? + space = config.summary_list_action_visually_hidden_space ? " " : nil + + tag.span("#{space}#{visually_hidden_text}", class: "govuk-visually-hidden") if visually_hidden_text.present? end end diff --git a/lib/govuk/components/engine.rb b/lib/govuk/components/engine.rb index 6ea59926..5cc9d3fa 100644 --- a/lib/govuk/components/engine.rb +++ b/lib/govuk/components/engine.rb @@ -100,6 +100,7 @@ def reset! default_link_new_tab_text: "(opens in new tab)", require_summary_list_action_visually_hidden_text: false, + summary_list_action_visually_hidden_space: false, enable_auto_table_scopes: true, }.freeze diff --git a/spec/components/govuk_component/configuration/summary_list_configuration_spec.rb b/spec/components/govuk_component/configuration/summary_list_configuration_spec.rb index 688e9a31..545a997f 100644 --- a/spec/components/govuk_component/configuration/summary_list_configuration_spec.rb +++ b/spec/components/govuk_component/configuration/summary_list_configuration_spec.rb @@ -58,5 +58,29 @@ end end end + + describe "summary_list_action_visually_hidden_space" do + before do + Govuk::Components.configure do |config| + config.summary_list_action_visually_hidden_space = true + end + end + + let(:visually_hidden_text) { "visually hidden info" } + + subject! do + render_inline(GovukComponent::SummaryListComponent.new) do |sl| + sl.with_row do |row| + row.with_key(text: "key one") + row.with_value(text: "value one") + row.with_action(text: "action one", href: "/action-one", visually_hidden_text: visually_hidden_text) + end + end + end + + specify "renders a span with a space inside the visually hidden text" do + expect(rendered_content).to have_tag("span", text: " #{visually_hidden_text}", with: { class: "govuk-visually-hidden" }) + end + end end end