From c439da934e3cde005e83483320f3c12060b27d58 Mon Sep 17 00:00:00 2001 From: Andrew Duthie <1779930+aduth@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:39:13 -0400 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + lib/simple_form/components/html5.rb | 7 ----- .../collection_check_boxes_input_test.rb | 6 ----- .../collection_radio_buttons_input_test.rb | 6 ----- test/inputs/collection_select_input_test.rb | 26 ------------------- test/inputs/country_input_test.rb | 6 ----- test/inputs/datetime_input_test.rb | 5 ---- test/inputs/hidden_input_test.rb | 3 +-- test/inputs/required_test.rb | 5 ---- test/inputs/time_zone_input_test.rb | 6 ----- 10 files changed, 2 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ead901b80..50712c8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * 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. * Try a slightly different approach to input lookups, without relying on regexp, to see if that helps with performance as originally intended. * Add support to Ruby 3.3. (no changes required.) +* Remove redundant `aria-required` attribute for required fields. [@aduth](https://github.com/aduth) ## 5.3.0 diff --git a/lib/simple_form/components/html5.rb b/lib/simple_form/components/html5.rb index b8e35c48c..9adc28cd1 100644 --- a/lib/simple_form/components/html5.rb +++ b/lib/simple_form/components/html5.rb @@ -10,10 +10,7 @@ def html5(wrapper_options = nil) @html5 = true input_html_options[:required] = input_html_required_option - input_html_options[:'aria-required'] = input_html_aria_required_option - input_html_options[:'aria-invalid'] = has_errors? || nil - nil end @@ -25,10 +22,6 @@ def input_html_required_option !options[:required].nil? ? required_field? : has_required? end - def input_html_aria_required_option - !options[:required].nil? ? (required_field? || nil) : (has_required? || nil) - end - def has_required? # We need to check browser_validations because # some browsers are still checking required even diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb index e42fc011b..139ac33fa 100644 --- a/test/inputs/collection_check_boxes_input_test.rb +++ b/test/inputs/collection_check_boxes_input_test.rb @@ -20,12 +20,6 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase assert_no_select 'input[required]' end - test 'collection input with check_boxes type does not generate aria-required html attribute' do - with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos] - assert_select 'input.required' - assert_no_select 'input[aria-required]' - end - test 'input does automatic collection translation for check_box types using defaults key' do store_translations(:en, simple_form: { options: { defaults: { gender: { male: 'Male', female: 'Female' } diff --git a/test/inputs/collection_radio_buttons_input_test.rb b/test/inputs/collection_radio_buttons_input_test.rb index dd841bcdb..94c5aaaa5 100644 --- a/test/inputs/collection_radio_buttons_input_test.rb +++ b/test/inputs/collection_radio_buttons_input_test.rb @@ -186,12 +186,6 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase assert_select 'input[type=radio][required]' end - test 'collection input with radio type generates aria-required html attribute' do - with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos] - assert_select 'input[type=radio].required' - assert_select 'input[type=radio][aria-required=true]' - end - test 'input radio does not wrap the collection by default' do with_input_for @user, :active, :radio_buttons diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index 477fa2abd..4125ed8d1 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -283,14 +283,12 @@ class CollectionSelectInputTest < ActionView::TestCase test "collection input generated aria-label should contain 'true'" do with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo" assert_select 'select.required' - assert_select 'select[aria-required=true]' end test 'collection input with select type does not generate required html attribute without blank option' do with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos] assert_select 'select.required' assert_no_select 'select[required]' - assert_no_select 'select[aria-required=true]' end 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 assert_select 'select[required]' end - test 'with a blank option, a collection input of type select has an aria-required html attribute' do - with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos] - assert_select 'select.required' - assert_select 'select[aria-required=true]' - end - - test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do - with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos] - assert_select 'select.required' - assert_no_select 'select[aria-required]' - end - - test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do - with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos] - assert_select 'select.required' - assert_select 'select[aria-required=true]' - end - - test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do - with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos] - assert_select 'select.required' - assert_select 'select[aria-required]' - end - test 'input allows disabled options with a lambda for collection select' do with_input_for @user, :name, :select, collection: %w[Carlos Antonio], disabled: ->(x) { x == "Carlos" } diff --git a/test/inputs/country_input_test.rb b/test/inputs/country_input_test.rb index c8968894c..7ab68c2f2 100644 --- a/test/inputs/country_input_test.rb +++ b/test/inputs/country_input_test.rb @@ -27,10 +27,4 @@ class CountryInputTest < ActionView::TestCase assert_select 'select.required' assert_select 'select[required]' end - - test 'input does generate select element with aria-required html attribute' do - with_input_for @user, :country, :country - assert_select 'select.required' - assert_select 'select[aria-required]' - end end diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb index 5b53ff4cb..79f50536a 100644 --- a/test/inputs/datetime_input_test.rb +++ b/test/inputs/datetime_input_test.rb @@ -44,11 +44,6 @@ class DateTimeInputWithHtml5Test < ActionView::TestCase assert_select 'input.required' assert_select 'input[required]' end - - test 'input has an aria-required html attribute' do - with_input_for @user, :delivery_time, :time, required: true, html5: true - assert_select 'input[aria-required=true]' - end end # Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper. diff --git a/test/inputs/hidden_input_test.rb b/test/inputs/hidden_input_test.rb index 4a751d1e6..d8740b04f 100644 --- a/test/inputs/hidden_input_test.rb +++ b/test/inputs/hidden_input_test.rb @@ -21,11 +21,10 @@ class HiddenInputTest < ActionView::TestCase assert_no_select 'label' end - test 'required/aria-required/optional options does not be generated for hidden inputs' do + test 'required/optional options does not be generated for hidden inputs' do with_input_for @user, :name, :hidden assert_no_select 'input.required' assert_no_select 'input[required]' - assert_no_select 'input[aria-required]' assert_no_select 'input.optional' assert_select 'input.hidden#user_name' end diff --git a/test/inputs/required_test.rb b/test/inputs/required_test.rb index 607ad1008..26ef7067e 100644 --- a/test/inputs/required_test.rb +++ b/test/inputs/required_test.rb @@ -35,7 +35,6 @@ class RequiredTest < ActionView::TestCase with_input_for @user, :name, :string assert_select 'input[type=text].required' assert_no_select 'input[type=text][required]' - assert_no_select 'input[type=text][aria-required]' end end @@ -44,7 +43,6 @@ class RequiredTest < ActionView::TestCase with_input_for @user, :name, :string, required: false assert_no_select 'input[type=text].required' assert_no_select 'input[type=text][required]' - assert_no_select 'input[type=text][aria-required]' end end @@ -53,7 +51,6 @@ class RequiredTest < ActionView::TestCase with_input_for @user, :name, :string, required: true assert_select 'input[type=text].required' assert_select 'input[type=text][required]' - assert_select 'input[type=text][aria-required]' end end @@ -65,7 +62,6 @@ class RequiredTest < ActionView::TestCase end assert_select 'input[type=text].required' assert_no_select 'input[type=text][required]' - assert_no_select 'input[type=text][aria-required]' end end end @@ -151,7 +147,6 @@ class RequiredTest < ActionView::TestCase concat f.input :name, required: false end assert_no_select 'input[type=text][required]' - assert_no_select 'input[type=text][aria-required]' end end end diff --git a/test/inputs/time_zone_input_test.rb b/test/inputs/time_zone_input_test.rb index 89051d3ec..7c2648522 100644 --- a/test/inputs/time_zone_input_test.rb +++ b/test/inputs/time_zone_input_test.rb @@ -27,10 +27,4 @@ class TimeZoneInputTest < ActionView::TestCase assert_select 'select.required' assert_select 'select[required]' end - - test 'input does generate select element with aria-required html attribute' do - with_input_for @user, :time_zone, :time_zone - assert_select 'select.required' - assert_select 'select[aria-required]' - end end