Skip to content

Commit

Permalink
Merge pull request #766 from alphagov/add-data-attributes-param-to-ra…
Browse files Browse the repository at this point in the history
…dio-button

Add ability to add data attributes to a single radio button
  • Loading branch information
1pretz1 authored Feb 26, 2019
2 parents 67b5d31 + 38c0aa3 commit 14aca54
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Enable ability to add data attributes to a single radio button (PR #766)

## 16.0.0

* BREAKING: Apply JS enhancements to govspeak (PR #751)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

data_attrs = { "aria-controls": conditional_id }
data_attrs["tracking-url"] = item[:url] if item.key?(:url)

if item.fetch(:data_attributes, {}).any?
data_attrs = data_attrs.merge(item[:data_attributes])
end
%>
<%= tag.div class: %w( gem-c-radio govuk-radios__item ) do %>
<%= check_box_tag name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ examples:
- value: "govuk-verify"
text: "Use GOV.UK Verify"
checked: true
with_data_attributes:
data:
name: "radio-group-data-attributes"
items:
- value: "cool-button"
text: "Best button in town"
data_attributes: { "contextual-guidance": "cool-buttons-guidance" }
- value: "no-data-attributes-button"
text: "Worst button in town"
with_custom_id_prefix:
data:
id_prefix: 'custom'
Expand Down
20 changes: 20 additions & 0 deletions spec/components/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ def component_name
assert_select ".govuk-radios__item .govuk-label--s"
end

it "renders a radio item with contextual-guidance data attribute" do
render_component(
name: "radio-group-data-attributes",
items: [
{
value: "cool-button",
text: "Best button in town",
data_attributes: { "contextual-guidance": "cool-buttons-guidance" },
},
{
value: "no-data-attributes-button",
text: "Worst button in town",
},
]
)

assert_select ".govuk-radios__item:first-child .govuk-radios__input[data-contextual-guidance=cool-buttons-guidance]"
assert_select ".govuk-radios__item:last-child .govuk-radios__input[data-contextual-guidance]", false
end

it "renders radio items with hint text" do
render_component(
name: "radio-group-hint-text",
Expand Down

0 comments on commit 14aca54

Please sign in to comment.