Skip to content

Commit

Permalink
Add data attributes to summary list 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 12699ea commit 87d0106
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
classes = "govuk-summary-list__row"
end
%>
<%= tag.div class: classes do %>
<%= tag.div class: classes, data: item[:data_attributes] do %>
<%= tag.dt item[:field], class: "govuk-summary-list__key" %>
<%= tag.dd item[:value], class: "govuk-summary-list__value" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ examples:
edit:
href: "edit-feedback"

with_data_attributes:
description: |
Data attributes can be passed to individual items within the component as shown.
data:
title: "Title, summary and body"
items:
- field: "Title"
value: "Ethical standards for public service providers"
data_attributes:
module: "something"

with_block:
description: Use the summary list with a block when you need to show an empty state message or load another component.
data:
Expand Down
15 changes: 15 additions & 0 deletions spec/components/summary_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,19 @@ def component_name
)
assert_select(".gem-c-summary-list.gem-c-summary-list--wide-title")
end

it "renders component with row data attributes" do
render_component(
title: "Title",
items: [
{
field: "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 87d0106

Please sign in to comment.