Skip to content

Commit

Permalink
Add CSS to the radio fieldset (#61)
Browse files Browse the repository at this point in the history
* added classes to the fieldset
  • Loading branch information
AndrewCowle committed Nov 21, 2022
1 parent 78d74f0 commit 03acb68
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
govuk-design-system-rails (0.9.6)
govuk-design-system-rails (0.9.7)

GEM
remote: https://rubygems.org/
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ It was originally extracted from Ruby applications built by the Office for Produ
You **must** include the [govuk-frontend](https://github.com/alphagov/govuk-frontend/) assets (CSS, JS, images, etc.) in your application in order to make use of this library. These assets are not bundled with this gem. This gem aims for parity with a specific version of the `govuk-frontend` library.

| This gem's version | Compatible with `govuk-frontend` version |
| --- | --- |
| 0.9.3 | 4.3.1 |
| 0.9.0 | 4.1.0 |
| 0.8.2 | 3.14.0 |
|--------------------| --- |
| 0.9.7 | 4.3.1 |
| 0.9.0 | 4.1.0 |
| 0.8.2 | 3.14.0 |

# Installation

Add the following to your project's Gemfile:

```ruby
gem "govuk-design-system-rails", git: "https://github.com/OfficeForProductSafetyAndStandards/govuk-design-system-rails", tag: "0.9.3", require: "govuk_design_system"
gem "govuk-design-system-rails", git: "https://github.com/OfficeForProductSafetyAndStandards/govuk-design-system-rails", tag: "0.9.7", require: "govuk_design_system"
```
and run `bundle install`

Expand Down
2 changes: 1 addition & 1 deletion app/views/components/_govuk_fieldset.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
fieldset_attributes = {
class: "govuk-fieldset",
class: ("govuk-fieldset #{local_assigns[:classes]}").strip,
}

fieldset_attributes.merge!(role: local_assigns[:role]) if local_assigns[:role]
Expand Down
2 changes: 1 addition & 1 deletion app/views/components/_govuk_radios.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<%= tag.div(class: form_group_classes) do %>
<% if local_assigns[:fieldset].present? %>
<%= govukFieldset(classes: "", describedBy: described_by, legend: local_assigns[:fieldset][:legend], attributes: local_assigns[:fieldset]) { radios_html } %>
<%= govukFieldset(classes: local_assigns[:fieldset][:classes], describedBy: described_by, legend: local_assigns[:fieldset][:legend], attributes: local_assigns[:fieldset]) { radios_html } %>
<% else %>
<%= radios_html %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion govuk_design_system-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)

Gem::Specification.new do |s|
s.name = "govuk-design-system-rails"
s.version = "0.9.6"
s.version = "0.9.7"
s.authors = %w[OfficeForProductSafetyAndStandards]
s.summary = "An implementation of the govuk-frontend macros in Ruby on Rails"
s.test_files = Dir["spec/**/*"]
Expand Down
59 changes: 59 additions & 0 deletions spec/helpers/govuk_design_system/radios_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,64 @@
]
})
end

it "returns the correct HTML when there is a fieldset css class" do
html = helper.govukRadios({
classes: "govuk-radios--inline",
idPrefix: "changed-name",
name: "changed-name",
fieldset: {
classes: "opss-grouping",
legend: {
text: "Have you changed your name?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
})

expect(html).to match_html(<<~HTML)
<div class="govuk-form-group">
<fieldset class="govuk-fieldset opss-grouping" aria-describedby="changed-name-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
Have you changed your name?
</h1>
</legend>
<div id="changed-name-hint" class="govuk-hint">
This includes changing your last name or spelling your name differently.
</div>
<div class="govuk-radios govuk-radios--inline" data-module="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-1" name="changed-name" type="radio" value="yes">
<label class="govuk-label govuk-radios__label" for="changed-name-1">
Yes
</label>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="changed-name-2" name="changed-name" type="radio" value="no">
<label class="govuk-label govuk-radios__label" for="changed-name-2">
No
</label>
</div>
</div>
</fieldset>
</div>
HTML
end
end
end

0 comments on commit 03acb68

Please sign in to comment.