Skip to content

Commit

Permalink
Merge pull request #4366 from alphagov/radio-button-component-wrapper
Browse files Browse the repository at this point in the history
Add component wrapper helper to radio component
  • Loading branch information
AshGDS authored Nov 7, 2024
2 parents fd5a89f + 8e586b5 commit 58bd8bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 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

* Add component wrapper helper to radio component ([PR #4366](https://github.com/alphagov/govuk_publishing_components/pull/4366))

## 45.1.0

* Add GA4 tracking for search autocomplete ([PR #4371](https://github.com/alphagov/govuk_publishing_components/pull/4371))
Expand Down
10 changes: 6 additions & 4 deletions app/views/govuk_publishing_components/components/_radio.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
hint_id = "hint-#{SecureRandom.hex(4)}" if hint
error_id = "error-#{SecureRandom.hex(4)}"

form_group_css_classes = %w(govuk-form-group)
form_group_css_classes << "govuk-form-group--error" if has_error
form_group_css_classes << shared_helper.get_margin_bottom
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("govuk-form-group")
component_helper.add_class("govuk-form-group--error") if has_error
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.set_id(id)

radio_classes = %w(govuk-radios)
radio_classes << "govuk-radios--small" if small
Expand All @@ -54,7 +56,7 @@
# check if any item is set as being conditional
has_conditional = items.any? { |item| item.is_a?(Hash) && item[:conditional] }
%>
<%= tag.div id: id, class: form_group_css_classes do %>
<%= tag.div(**component_helper.all_attributes) do %>
<%= tag.fieldset class: "govuk-fieldset", "aria-describedby": aria do %>
<% if heading.present? %>
<%= tag.legend class: legend_classes do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ body: |
You can also use 'or' as an item to break up radios.
If JavaScript is disabled a conditionally revealed content expands fully. All of the functionality (including aria attributes) are added using JavaScript.
uses_component_wrapper_helper: true
accessibility_criteria: |
Radio buttons should
Expand Down

0 comments on commit 58bd8bd

Please sign in to comment.