Skip to content

Commit

Permalink
Switch action_suffix back to card_title
Browse files Browse the repository at this point in the history
This matches the nunjucks implementation more closely but could cause
confusion because `card: { title: "Hi" }` and `card_title: "Hi"` now do
very different things.

Not sure whether this commit will remain, but adding it for comparison.
  • Loading branch information
peteryates committed Dec 12, 2023
1 parent 0bd9456 commit 452b5c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 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, :card_title

renders_many :rows, ->(classes: [], html_attributes: {}, &block) do
GovukComponent::SummaryListComponent::RowComponent.new(
show_actions_column: @show_actions_column,
action_suffix: action_suffix || card&.title,
card_title: card_title || 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: {})
def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: {}, card_title: nil, classes: [], html_attributes: {})
@borders = borders
@show_actions_column = actions
@card = GovukComponent::SummaryListComponent::CardComponent.new(**card) if card.present?
@action_suffix = action_suffix
@card_title = card_title

super(classes: classes, html_attributes: html_attributes)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class GovukComponent::SummaryListComponent::ActionComponent < GovukComponent::Base
attr_reader :href, :text, :visually_hidden_text, :action_suffix, :attributes, :classes
attr_reader :href, :text, :visually_hidden_text, :card_title, :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, card_title: nil, classes: [], html_attributes: {})
@visually_hidden_text = visually_hidden_text

if config.require_summary_list_action_visually_hidden_text && visually_hidden_text == false
Expand All @@ -12,7 +12,7 @@ def initialize(href: nil, text: 'Change', visually_hidden_text: false, action_su

@href = href
@text = text
@action_suffix = action_suffix
@card_title = card_title
end

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

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

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, :card_title

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,
card_title: card_title,
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, card_title: nil, classes: [], html_attributes: {})
@show_actions_column = show_actions_column
@action_suffix = action_suffix
@card_title = card_title

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 card_title 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" }, card_title: "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 card_title 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 card_title:" do
subject! do
render_inline(described_class.new(action_suffix: "Hi", **kwargs)) do |component|
render_inline(described_class.new(card_title: "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 452b5c4

Please sign in to comment.