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 custom heading level option to radio component #1951

Merged
merged 2 commits into from
Mar 2, 2021
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

* Add border option to breadcrumb ([PR #1952])(https://github.com/alphagov/govuk_publishing_components/pull/1952) MINOR
* Add custom heading level option to radio component ([PR #1951](https://github.com/alphagov/govuk_publishing_components/pull/1951))

## 24.3.1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
id ||= nil
id_prefix ||= "radio-#{SecureRandom.hex(4)}"
items ||= []
Expand Down Expand Up @@ -54,7 +55,7 @@
<% end %>
<% else %>
<%= tag.legend class: legend_classes do %>
<%= tag.h2 heading, class: "govuk-fieldset__heading" %>
<%= content_tag(shared_helper.get_heading_level, heading, class: "govuk-fieldset__heading") %>
<% end %>
<% end %>
<% end %>
Expand Down
15 changes: 14 additions & 1 deletion app/views/govuk_publishing_components/components/docs/radio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ examples:
text: "Blue"
with_custom_heading_size:
description: |
This allows the size of the legend to be changed. Valid options are s, m, l, xl, defaulting to m if no option is passed.
This allows the size of the legend to be changed. Valid options are s, m, l, xl, defaulting to m if no option is passed.
If the is_page_heading option is true and heading_size is not set, the text size will be xl.
danacotoran marked this conversation as resolved.
Show resolved Hide resolved
data:
Expand All @@ -198,6 +198,19 @@ examples:
text: "Green"
- value: "blue"
text: "Blue"
with_custom_heading_level:
description: This allows the heading level to be changed. Heading level will default to `h2` if nothing is passed.
data:
name: "radio-group-description"
heading: "What is your favourite colour?"
heading_level: 3
items:
- value: "red"
text: "Red"
- value: "green"
text: "Green"
- value: "blue"
text: "Blue"
with_hint_text_on_radios:
data:
name: "radio-group-hint-text"
Expand Down
27 changes: 27 additions & 0 deletions spec/components/radio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ def component_name
assert_select ".govuk-fieldset__legend.govuk-fieldset__legend--m", "What is your favourite skittle?"
end

it "renders radio-group with h2 heading level by default" do
render_component(
name: "favourite-skittle",
heading: "What is your favourite skittle?",
items: [
{ label: "Red", value: "red" },
{ label: "Green", value: "green" },
{ label: "Blue", value: "blue" },
],
)
assert_select "h2.govuk-fieldset__heading", text: "What is your favourite skittle?"
end

it "renders radio-group custom heading level if custom heading level is passed" do
render_component(
name: "favourite-skittle",
heading: "What is your favourite skittle?",
heading_level: 4,
items: [
{ label: "Red", value: "red" },
{ label: "Green", value: "green" },
{ label: "Blue", value: "blue" },
],
)
assert_select "h4.govuk-fieldset__heading", text: "What is your favourite skittle?"
end

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