]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: do not add aria-describedby to hidden inputs 12496/head
authorAntti Hukkanen <antti.hukkanen@mainiotech.fi>
Wed, 2 Nov 2022 13:47:41 +0000 (15:47 +0200)
committerAntti Hukkanen <antti.hukkanen@mainiotech.fi>
Wed, 2 Nov 2022 13:47:41 +0000 (15:47 +0200)
js/foundation.abide.js
test/javascript/components/abide.js

index cd1aca3490707333a2bd1bdfe60d1c68ed959f53..6bf27f507b896456148bbaafce086e25baf6a523 100644 (file)
@@ -328,6 +328,7 @@ class Abide extends Plugin {
   }
 
   addA11yErrorDescribe($el, $error) {
+    if ($el.attr('type') === 'hidden') return;
     if (typeof $el.attr('aria-describedby') !== 'undefined') return;
 
     // Set [aria-describedby] on the input toward the first form error if it is not set
index 19ea148db168440c0f8d189fa3cb0b21507154d5..c49ee1ae86b6bb4422119756a351be3dc88475d0 100644 (file)
@@ -157,6 +157,19 @@ describe('Abide', function() {
       $html.find('input').should.not.have.attr('aria-describedby', 'test-error');
     });
 
+    it('does not add [aria-describedby] to the field if the input is hidden', function() {
+      $html = $(`
+        <form data-abide>
+          <input type="hidden" id="test-input">
+          <span class="form-error is-visible" id="test-error">Form error</span>
+        </form>
+      `).appendTo('body');
+      plugin = new Foundation.Abide($html, {});
+      plugin.addA11yAttributes($html.find('input'));
+
+      $html.find('input').should.not.have.attr('aria-describedby', 'test-error');
+    });
+
     it('adds [aria-describedby] to the field if the form error is shown after a validation error', function() {
       $html = $(`
         <form data-abide>