diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 35814589b3..cdfc0e1f06 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -139,7 +139,9 @@ public static function setAttributes(&$element, $class = []) { if (!empty($element['#required'])) { $element['#attributes']['class'][] = 'required'; $element['#attributes']['required'] = 'required'; - $element['#attributes']['aria-required'] = 'true'; + if (($element['#type'] ?? NULL) !== 'checkbox') { + $element['#attributes']['aria-required'] = 'true'; + } } if (isset($element['#parents']) && isset($element['#errors']) && !empty($element['#validated'])) { $element['#attributes']['class'][] = 'error'; diff --git a/core/modules/system/tests/src/Functional/Form/CheckboxTest.php b/core/modules/system/tests/src/Functional/Form/CheckboxTest.php index 024be19975..bfbdbd4ef0 100644 --- a/core/modules/system/tests/src/Functional/Form/CheckboxTest.php +++ b/core/modules/system/tests/src/Functional/Form/CheckboxTest.php @@ -102,4 +102,13 @@ public function testFormCheckbox() { } } + /** + * Tests that checkbox has no aria required attribute. + */ + public function testFormCheckboxHasNoAriaRequiredAtt() { + $this->drupalGet('/form-test/checkbox'); + $element = $this->cssSelect('input[aria-required]'); + $this->assertEmpty($element); + } + }