Skip to content

Commit

Permalink
Add configuration option for visually hidden space on SummaryListComp…
Browse files Browse the repository at this point in the history
…onent::ActionComponent
  • Loading branch information
paulodeon committed Mar 1, 2023
1 parent 730360a commit 42fd821
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
1 change: 1 addition & 0 deletions lib/govuk/components/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 42fd821

Please sign in to comment.