Skip to content

Commit

Permalink
Add small option to radio component
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Apr 15, 2019
1 parent d7a5343 commit 4a00702
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

label ||= nil
heading ||= nil
small ||= false
is_page_heading ||= false
hint ||= nil
error_message ||= nil
Expand All @@ -16,6 +17,9 @@
form_group_css_classes = %w(govuk-form-group)
form_group_css_classes << "govuk-form-group--error" if has_error

radio_classes = %w(govuk-radios)
radio_classes << "govuk-radios--small" if small

aria = "#{hint_id} #{"#{error_id}" if has_error}".strip if hint or has_error

# check if any item is set as being conditional
Expand Down Expand Up @@ -53,7 +57,7 @@
} %>
<% end %>

<%= content_tag :div, class: "govuk-radios",
<%= content_tag :div, class: radio_classes,
data: {
module: ('radios' if has_conditional)
} do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ examples:
text: "Use Government Gateway"
- value: "govuk-verify"
text: "Use GOV.UK Verify"
with_small_radios:
data:
name: "radio-group"
small: true
items:
- value: "government-gateway"
text: "Use Government Gateway"
- value: "govuk-verify"
text: "Use GOV.UK Verify"
with_bold:
description: 'Used to provide better contrast between long labels and hint text, Note that the `:or` option [is documented as a string due to a bug](https://github.com/alphagov/govuk_publishing_components/issues/102)'
data:
Expand Down
19 changes: 19 additions & 0 deletions spec/components/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ def component_name
assert_select ".govuk-radios__item:last-child .govuk-radios__label", text: "Use GOV.UK Verify"
end

it "renders small radios" do
render_component(
name: "radio-group-multiple-items",
small: true,
items: [
{
value: "government-gateway",
text: "Use Government Gateway"
},
{
value: "govuk-verify",
text: "Use GOV.UK Verify"
}
]
)

assert_select ".govuk-radios.govuk-radios--small"
end

it "renders radio-group with a legend" do
render_component(
name: "favourite-smartie",
Expand Down

0 comments on commit 4a00702

Please sign in to comment.