diff --git a/lib/simple_form/components/html5.rb b/lib/simple_form/components/html5.rb
index cb513703..545b8f16 100644
--- a/lib/simple_form/components/html5.rb
+++ b/lib/simple_form/components/html5.rb
@@ -7,7 +7,10 @@ module SimpleForm
def html5
@html5 = true
- input_html_options[:required] = true if has_required?
+ if has_required?
+ input_html_options[:required] = true
+ input_html_options['aria-required'] = true
+ end
nil
end
diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb
index 3fc6a424..ab23bc3c 100644
--- a/test/inputs/collection_check_boxes_input_test.rb
+++ b/test/inputs/collection_check_boxes_input_test.rb
@@ -23,6 +23,12 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
assert_no_select 'input[required]'
end
+ test 'collection input with check_boxes type should not generate aria-required html attribute' do
+ with_input_for @user, :name, :check_boxes, collection: ['Jose' , 'Carlos']
+ assert_select 'input.required'
+ assert_no_select 'input[aria-required]'
+ end
+
test 'input should do 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 745858a2..1d77bb1a 100644
--- a/test/inputs/collection_radio_buttons_input_test.rb
+++ b/test/inputs/collection_radio_buttons_input_test.rb
@@ -140,6 +140,12 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
assert_select 'input[type=radio][required]'
end
+ test 'collection input with radio type should generate aria-required html attribute' do
+ with_input_for @user, :name, :radio_buttons, collection: ['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 c102696e..56968420 100644
--- a/test/inputs/collection_select_input_test.rb
+++ b/test/inputs/collection_select_input_test.rb
@@ -176,6 +176,7 @@ class CollectionSelectInputTest < ActionView::TestCase
with_input_for @user, :name, :select, include_blank: false, collection: ['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 should generate required html attribute without blank option' do
@@ -190,6 +191,30 @@ 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: ['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: ['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: ['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: ['Jose' , 'Carlos']
+ assert_select 'select.required'
+ assert_select 'select[aria-required]'
+ end
+
test 'input should allow disabled options with a lambda for collection select' do
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
disabled: lambda { |x| x == "Carlos" }
diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb
index e224ea91..404f4e4b 100644
--- a/test/inputs/datetime_input_test.rb
+++ b/test/inputs/datetime_input_test.rb
@@ -96,4 +96,10 @@ class DateTimeInputTest < ActionView::TestCase
assert_select 'select.required'
assert_select 'select[required]'
end
+
+ test 'date time input has an aria-required html attribute' do
+ with_input_for @user, :delivery_time, :time, required: true
+ assert_select 'select.required'
+ assert_select 'select[aria-required=true]'
+ end
end
diff --git a/test/inputs/hidden_input_test.rb b/test/inputs/hidden_input_test.rb
index d86e5cba..19857f86 100644
--- a/test/inputs/hidden_input_test.rb
+++ b/test/inputs/hidden_input_test.rb
@@ -20,10 +20,11 @@ class HiddenInputTest < ActionView::TestCase
assert_no_select 'label'
end
- test 'required/optional options should not be generated for hidden inputs' do
+ test 'required/aria-required/optional options should 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/priority_input_test.rb b/test/inputs/priority_input_test.rb
index b316ddf7..a7ce14c8 100644
--- a/test/inputs/priority_input_test.rb
+++ b/test/inputs/priority_input_test.rb
@@ -40,4 +40,10 @@ class PriorityInputTest < ActionView::TestCase
assert_select 'select.required'
assert_no_select 'select[required]'
end
+
+ test 'priority input should not generate invalid aria-required html attribute' do
+ with_input_for @user, :country, :country
+ assert_select 'select.required'
+ assert_no_select 'select[aria-required]'
+ end
end