Skip to content

Commit

Permalink
Add data attributes to Summary Card rows
Browse files Browse the repository at this point in the history
This allows users to add data attributes (for example, when initialising
Javascript modules) to individual rows
  • Loading branch information
pezholio committed Oct 23, 2024
1 parent 2390d9b commit 12699ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions spec/components/summary_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 12699ea

Please sign in to comment.