Skip to content

Commit

Permalink
Merge pull request #3528 from citizensadvice/fix/radio-button-group-e…
Browse files Browse the repository at this point in the history
…rrors

Fix/radio button group errors
  • Loading branch information
cnorthwood authored Jan 22, 2025
2 parents 11bb5f1 + df2eb85 commit f54d532
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
initNavigation();
```

**Fix**
- Improves screen reader experience when interacting with checkbox and radio groups in an error state

## v6.3.0

### 5 December 2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<p class="cads-form-field__hint"><%= hint %></p>
<% end %>
<% if error? %>
<p class="cads-form-field__error-message"><%= error_message %></p>
<p class="cads-form-field__error-message" <% if error? %> id="<%= error_id %>"<% end %>><%= error_message %></p>
<% end %>
<% inputs.each_with_index do |input, index| %>
<div class="cads-form-group__item">
<%= tag.input(class: "cads-form-group__input", **input.attributes(name, id, index)) %>
<%= tag.input(class: "cads-form-group__input", **input.attributes(name, id, index, error: error?)) %>
<label class="cads-form-group__label" for="<%= input.attributes(name, id, index)[:id] %>">
<%= input.label %>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def error?
@error_message.present?
end

def error_id
"#{name}-error"
end

def optional?
@optional.present?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@

it { is_expected.to have_css ".cads-form-field--has-error" }
it { is_expected.to have_text "This is the error message" }
it { is_expected.to have_css "[aria-describedby='checkboxes-error']" }
it { is_expected.to have_css "#checkboxes-error" }
it { is_expected.to have_css "input[aria-invalid]", count: 2 }
end

context "when an hint text is provided" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@

it { is_expected.to have_css ".cads-form-field--has-error" }
it { is_expected.to have_text "This is the error message" }
it { is_expected.to have_css "[aria-describedby='radio-group-error']" }
it { is_expected.to have_css "#radio-group-error" }
it { is_expected.to have_css "input[aria-invalid]", count: 2 }
end

context "when an hint text is provided" do
Expand Down

0 comments on commit f54d532

Please sign in to comment.