diff --git a/app/views/govuk_publishing_components/components/_summary_card.html.erb b/app/views/govuk_publishing_components/components/_summary_card.html.erb index eb137bcc98..aca4b34977 100644 --- a/app/views/govuk_publishing_components/components/_summary_card.html.erb +++ b/app/views/govuk_publishing_components/components/_summary_card.html.erb @@ -28,7 +28,7 @@ <%= tag.div class: "govuk-summary-card__content" do %> <%= tag.dl class: "govuk-summary-list" do %> <% rows.each do |row| %> - <%= tag.div class: "govuk-summary-list__row" do %> + <%= tag.div class: "govuk-summary-list__row", data: row[:data_attributes] do %> <%= tag.dt class: "govuk-summary-list__key" do %> <%= row[:key] %> <% end %> diff --git a/app/views/govuk_publishing_components/components/docs/summary_card.yml b/app/views/govuk_publishing_components/components/docs/summary_card.yml index 71553d93eb..9b668de054 100644 --- a/app/views/govuk_publishing_components/components/docs/summary_card.yml +++ b/app/views/govuk_publishing_components/components/docs/summary_card.yml @@ -91,3 +91,13 @@ examples: - label: View href: "#1" opens_in_new_tab: true + with_row_data_attributes: + description: | + Data attributes can be passed to individual rows within the component as shown. + data: + title: Title + rows: + - key: key one + value: value1 + data_attributes: + module: "something" diff --git a/spec/components/summary_card_spec.rb b/spec/components/summary_card_spec.rb index 7d2c562fe3..cf34f3ec42 100644 --- a/spec/components/summary_card_spec.rb +++ b/spec/components/summary_card_spec.rb @@ -154,4 +154,19 @@ def component_name assert_select '.govuk-summary-list__row .govuk-link[href="#1"]', text: "View One (opens in new tab)" assert_select '.govuk-summary-list__row .govuk-link[target="_blank"]', text: "View One (opens in new tab)" end + + it "renders component with row data attributes" do + render_component( + title: "Title", + rows: [ + { + key: "One", + value: "Value 1", + data_attributes: { module: "something" }, + }, + ], + ) + + assert_select ".govuk-summary-list__row[data-module='something']", text: /One/ + end end