Skip to content

Commit

Permalink
Switch action_suffix to visually_hidden_action_suffix
Browse files Browse the repository at this point in the history
Having deliberated a bit over naming I think this is best. Originally it
was `card_title` but I think it's misleading because it doesn't actually
set a card's title, and `card_title: "xyz"` looks quite similar to
`card: { title: "xyz" }`, but they do totally different things.

This name is an improvement over `action_suffix` because it tells the
dev that it's visually hidden and comes after the action. It's inkeeping
with other visually hidden params like `visually_hidden_text` too.
  • Loading branch information
peteryates committed Dec 21, 2023
1 parent 0e87796 commit 7f3d526
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
14 changes: 7 additions & 7 deletions app/components/govuk_component/summary_list_component.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module GovukComponent
class SummaryListComponent < GovukComponent::Base
attr_reader :borders, :actions, :card, :action_suffix
attr_reader :borders, :actions, :card, :visually_hidden_action_suffix

renders_many :rows, ->(classes: [], html_attributes: {}, &block) do
GovukComponent::SummaryListComponent::RowComponent.new(
show_actions_column: @show_actions_column,
action_suffix: action_suffix || card&.title,
visually_hidden_action_suffix: visually_hidden_action_suffix || card&.title,
classes: classes,
html_attributes: html_attributes,
&block
)
end

def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: {}, action_suffix: nil, classes: [], html_attributes: {})
@borders = borders
@show_actions_column = actions
@card = GovukComponent::SummaryListComponent::CardComponent.new(**card) if card.present?
@action_suffix = action_suffix
def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: {}, visually_hidden_action_suffix: nil, classes: [], html_attributes: {})
@borders = borders
@show_actions_column = actions
@card = GovukComponent::SummaryListComponent::CardComponent.new(**card) if card.present?
@visually_hidden_action_suffix = visually_hidden_action_suffix

super(classes: classes, html_attributes: html_attributes)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
class GovukComponent::SummaryListComponent::ActionComponent < GovukComponent::Base
attr_reader :href, :text, :visually_hidden_text, :action_suffix, :attributes, :classes
attr_reader :href, :text, :visually_hidden_text, :visually_hidden_action_suffix, :attributes, :classes

def initialize(href: nil, text: 'Change', visually_hidden_text: false, action_suffix: nil, classes: [], html_attributes: {})
def initialize(href: nil, text: 'Change', visually_hidden_text: false, visually_hidden_action_suffix: nil, classes: [], html_attributes: {})
@visually_hidden_text = visually_hidden_text

if config.require_summary_list_action_visually_hidden_text && visually_hidden_text == false
fail(ArgumentError, "missing keyword: visually_hidden_text")
end

super(classes: classes, html_attributes: html_attributes)

@href = href
@text = text
@action_suffix = action_suffix
@href = href
@text = text
@visually_hidden_action_suffix = visually_hidden_action_suffix
end

def render?
Expand All @@ -38,7 +37,7 @@ def action_text
end

def visually_hidden_content
return "#{visually_hidden_text} (#{action_suffix})" if action_suffix
return "#{visually_hidden_text} (#{visually_hidden_action_suffix})" if visually_hidden_action_suffix

visually_hidden_text
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class GovukComponent::SummaryListComponent::RowComponent < GovukComponent::Base
attr_reader :href, :visually_hidden_text, :show_actions_column, :action_suffix
attr_reader :href, :visually_hidden_text, :show_actions_column, :visually_hidden_action_suffix

renders_one :key, GovukComponent::SummaryListComponent::KeyComponent
renders_one :value, GovukComponent::SummaryListComponent::ValueComponent
Expand All @@ -8,16 +8,16 @@ class GovukComponent::SummaryListComponent::RowComponent < GovukComponent::Base
href: href,
text: text,
visually_hidden_text: visually_hidden_text,
action_suffix: action_suffix,
visually_hidden_action_suffix: visually_hidden_action_suffix,
classes: classes,
html_attributes: html_attributes,
&block
)
end

def initialize(show_actions_column: nil, action_suffix: nil, classes: [], html_attributes: {})
def initialize(show_actions_column: nil, visually_hidden_action_suffix: nil, classes: [], html_attributes: {})
@show_actions_column = show_actions_column
@action_suffix = action_suffix
@visually_hidden_action_suffix = visually_hidden_action_suffix

super(classes: classes, html_attributes: html_attributes)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/components/govuk_component/summary_list_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,24 @@
end
end

context "when the action_suffix is present" do
context "when the visually_hidden_action_suffix is present" do
subject! do
render_inline(described_class.new(card: { title: "Hi" }, action_suffix: "Hello", **kwargs)) do |component|
render_inline(described_class.new(card: { title: "Hi" }, visually_hidden_action_suffix: "Hello", **kwargs)) do |component|
component.with_row { |row| helper.safe_join([row.with_key(text: "Key"), row.with_value(text: "Value"), row.with_action(href: "/a", visually_hidden_text: "this row")]) }
end
end

specify "the action_suffix overrides the card's title in action links" do
specify "the visually_hidden_action_suffix overrides the card's title in action links" do
expect(rendered_content).to have_tag("dd", with: { class: "govuk-summary-list__actions" }) do
with_tag("span", with: { class: "govuk-visually-hidden" }, text: %r{this row \(Hello\)})
end
end
end
end

context "when the summary list is manually placed within a card and the title is set with action_suffix:" do
context "when the summary list is manually placed within a card and the title is set with visually_hidden_action_suffix:" do
subject! do
render_inline(described_class.new(action_suffix: "Hi", **kwargs)) do |component|
render_inline(described_class.new(visually_hidden_action_suffix: "Hi", **kwargs)) do |component|
component.with_row { |row| helper.safe_join([row.with_key(text: "Key"), row.with_value(text: "Value"), row.with_action(href: "/a", visually_hidden_text: "this row")]) }
end
end
Expand Down

0 comments on commit 7f3d526

Please sign in to comment.