Skip to content

Commit c439da9

Browse files
authored
Remove aria-required for required fields in HTML5 (#1823)
The reason is that the fields are already assigned the required attribute which would be used by assistive technology to convey the field requirement
1 parent d3a5949 commit c439da9

10 files changed

+2
-69
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Revert "Speed up input mapping lookup by avoiding rescuing exceptions" from v5.3.0, it caused a regression on dev/test environments with custom inputs.
88
* Try a slightly different approach to input lookups, without relying on regexp, to see if that helps with performance as originally intended.
99
* Add support to Ruby 3.3. (no changes required.)
10+
* Remove redundant `aria-required` attribute for required fields. [@aduth](https://github.com/aduth)
1011

1112
## 5.3.0
1213

lib/simple_form/components/html5.rb

-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ def html5(wrapper_options = nil)
1010
@html5 = true
1111

1212
input_html_options[:required] = input_html_required_option
13-
input_html_options[:'aria-required'] = input_html_aria_required_option
14-
1513
input_html_options[:'aria-invalid'] = has_errors? || nil
16-
1714
nil
1815
end
1916

@@ -25,10 +22,6 @@ def input_html_required_option
2522
!options[:required].nil? ? required_field? : has_required?
2623
end
2724

28-
def input_html_aria_required_option
29-
!options[:required].nil? ? (required_field? || nil) : (has_required? || nil)
30-
end
31-
3225
def has_required?
3326
# We need to check browser_validations because
3427
# some browsers are still checking required even

test/inputs/collection_check_boxes_input_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
2020
assert_no_select 'input[required]'
2121
end
2222

23-
test 'collection input with check_boxes type does not generate aria-required html attribute' do
24-
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
25-
assert_select 'input.required'
26-
assert_no_select 'input[aria-required]'
27-
end
28-
2923
test 'input does automatic collection translation for check_box types using defaults key' do
3024
store_translations(:en, simple_form: { options: { defaults: {
3125
gender: { male: 'Male', female: 'Female' }

test/inputs/collection_radio_buttons_input_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
186186
assert_select 'input[type=radio][required]'
187187
end
188188

189-
test 'collection input with radio type generates aria-required html attribute' do
190-
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
191-
assert_select 'input[type=radio].required'
192-
assert_select 'input[type=radio][aria-required=true]'
193-
end
194-
195189
test 'input radio does not wrap the collection by default' do
196190
with_input_for @user, :active, :radio_buttons
197191

test/inputs/collection_select_input_test.rb

-26
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,12 @@ class CollectionSelectInputTest < ActionView::TestCase
283283
test "collection input generated aria-label should contain 'true'" do
284284
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
285285
assert_select 'select.required'
286-
assert_select 'select[aria-required=true]'
287286
end
288287

289288
test 'collection input with select type does not generate required html attribute without blank option' do
290289
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
291290
assert_select 'select.required'
292291
assert_no_select 'select[required]'
293-
assert_no_select 'select[aria-required=true]'
294292
end
295293

296294
test 'collection input with select type with multiple attribute generates required html attribute without blank option' do
@@ -305,30 +303,6 @@ class CollectionSelectInputTest < ActionView::TestCase
305303
assert_select 'select[required]'
306304
end
307305

308-
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
309-
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
310-
assert_select 'select.required'
311-
assert_select 'select[aria-required=true]'
312-
end
313-
314-
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
315-
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
316-
assert_select 'select.required'
317-
assert_no_select 'select[aria-required]'
318-
end
319-
320-
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
321-
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
322-
assert_select 'select.required'
323-
assert_select 'select[aria-required=true]'
324-
end
325-
326-
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
327-
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
328-
assert_select 'select.required'
329-
assert_select 'select[aria-required]'
330-
end
331-
332306
test 'input allows disabled options with a lambda for collection select' do
333307
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
334308
disabled: ->(x) { x == "Carlos" }

test/inputs/country_input_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,4 @@ class CountryInputTest < ActionView::TestCase
2727
assert_select 'select.required'
2828
assert_select 'select[required]'
2929
end
30-
31-
test 'input does generate select element with aria-required html attribute' do
32-
with_input_for @user, :country, :country
33-
assert_select 'select.required'
34-
assert_select 'select[aria-required]'
35-
end
3630
end

test/inputs/datetime_input_test.rb

-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ class DateTimeInputWithHtml5Test < ActionView::TestCase
4444
assert_select 'input.required'
4545
assert_select 'input[required]'
4646
end
47-
48-
test 'input has an aria-required html attribute' do
49-
with_input_for @user, :delivery_time, :time, required: true, html5: true
50-
assert_select 'input[aria-required=true]'
51-
end
5247
end
5348

5449
# Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper.

test/inputs/hidden_input_test.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ class HiddenInputTest < ActionView::TestCase
2121
assert_no_select 'label'
2222
end
2323

24-
test 'required/aria-required/optional options does not be generated for hidden inputs' do
24+
test 'required/optional options does not be generated for hidden inputs' do
2525
with_input_for @user, :name, :hidden
2626
assert_no_select 'input.required'
2727
assert_no_select 'input[required]'
28-
assert_no_select 'input[aria-required]'
2928
assert_no_select 'input.optional'
3029
assert_select 'input.hidden#user_name'
3130
end

test/inputs/required_test.rb

-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class RequiredTest < ActionView::TestCase
3535
with_input_for @user, :name, :string
3636
assert_select 'input[type=text].required'
3737
assert_no_select 'input[type=text][required]'
38-
assert_no_select 'input[type=text][aria-required]'
3938
end
4039
end
4140

@@ -44,7 +43,6 @@ class RequiredTest < ActionView::TestCase
4443
with_input_for @user, :name, :string, required: false
4544
assert_no_select 'input[type=text].required'
4645
assert_no_select 'input[type=text][required]'
47-
assert_no_select 'input[type=text][aria-required]'
4846
end
4947
end
5048

@@ -53,7 +51,6 @@ class RequiredTest < ActionView::TestCase
5351
with_input_for @user, :name, :string, required: true
5452
assert_select 'input[type=text].required'
5553
assert_select 'input[type=text][required]'
56-
assert_select 'input[type=text][aria-required]'
5754
end
5855
end
5956

@@ -65,7 +62,6 @@ class RequiredTest < ActionView::TestCase
6562
end
6663
assert_select 'input[type=text].required'
6764
assert_no_select 'input[type=text][required]'
68-
assert_no_select 'input[type=text][aria-required]'
6965
end
7066
end
7167
end
@@ -151,7 +147,6 @@ class RequiredTest < ActionView::TestCase
151147
concat f.input :name, required: false
152148
end
153149
assert_no_select 'input[type=text][required]'
154-
assert_no_select 'input[type=text][aria-required]'
155150
end
156151
end
157152
end

test/inputs/time_zone_input_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,4 @@ class TimeZoneInputTest < ActionView::TestCase
2727
assert_select 'select.required'
2828
assert_select 'select[required]'
2929
end
30-
31-
test 'input does generate select element with aria-required html attribute' do
32-
with_input_for @user, :time_zone, :time_zone
33-
assert_select 'select.required'
34-
assert_select 'select[aria-required]'
35-
end
3630
end

0 commit comments

Comments
 (0)