Skip to content

Commit

Permalink
Merge pull request #4252 from alphagov/radio-cb-hidden-legend
Browse files Browse the repository at this point in the history
Allow visually hiding legend on `radio` component
  • Loading branch information
csutter authored Sep 24, 2024
2 parents 112d213 + 83a8f13 commit 35dc939
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
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

* Add `ostruct` as an explicit dependency ([PR #4251](https://github.com/alphagov/govuk_publishing_components/pull/4251))
* Allow visually hiding legend on `radio` component ([PR #4252](https://github.com/alphagov/govuk_publishing_components/pull/4252))

## 43.4.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
heading ||= nil
heading_caption ||= nil
heading_size ||= nil
visually_hidden_heading ||= false
small ||= false
inline ||= false
heading_level = shared_helper.get_heading_level
Expand Down Expand Up @@ -46,6 +47,7 @@

legend_classes = %w(govuk-fieldset__legend)
legend_classes << "govuk-fieldset__legend--#{size}"
legend_classes << "govuk-visually-hidden" if visually_hidden_heading

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

Expand Down
15 changes: 15 additions & 0 deletions app/views/govuk_publishing_components/components/docs/radio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ examples:
text: "Yes"
- value: "no"
text: "No"
with_visually_hidden_heading:
description: |
If the heading/legend on the radios is not required, it can be visually hidden using this
option. It will still be visible to screen readers.
data:
name: "radio-group-visually-hidden-heading"
heading: "What is your favourite colour?"
visually_hidden_heading: true
items:
- value: "red"
text: "Red"
- value: "green"
text: "Green"
- value: "blue"
text: "Blue"
with_description:
data:
name: "radio-group-description"
Expand Down
11 changes: 11 additions & 0 deletions spec/components/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ def component_name
assert_select "h4.govuk-fieldset__heading", text: "What is your favourite skittle?"
end

it "renders radio-group with a visually hidden heading if visually_hidden_heading is passed" do
render_component(
name: "favourite-skittle",
heading: "What is your favourite skittle?",
heading_level: 4,
visually_hidden_heading: true,
)

assert_select "legend.govuk-visually-hidden", "What is your favourite skittle?"
end

it "renders radio-group with bold labels" do
render_component(
name: "radio-group-bold-labels",
Expand Down

0 comments on commit 35dc939

Please sign in to comment.