Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data attributes to summary cards and lists #4331

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## Unreleased

* Layout super nav header: Correct URL for search form ([PR #4341](https://github.com/alphagov/govuk_publishing_components/pull/4341))
* Add support for data attributes in Summary List and Summary Card rows ([PR #4331](https://github.com/alphagov/govuk_publishing_components/pull/4331))

## 44.8.0

Expand Down
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] 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 @@ -77,7 +77,7 @@
classes = "govuk-summary-list__row"
end
%>
<%= tag.div class: classes do %>
<%= tag.div class: classes, data: item[:data] 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 @@ -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:
module: "something"
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:
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_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: { module: "something" },
},
],
)

assert_select ".govuk-summary-list__row[data-module='something']", text: /One/
end
end
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: { module: "something" },
},
],
)

assert_select ".govuk-summary-list__row[data-module='something']", text: /One/
end
end
Loading