From dff781f8a50f78f46a1e5d32472d25676c79803d Mon Sep 17 00:00:00 2001 From: Antti Hukkanen Date: Wed, 2 Nov 2022 15:47:41 +0200 Subject: [PATCH] fix: do not add aria-describedby to hidden inputs --- js/foundation.abide.js | 1 + test/javascript/components/abide.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/js/foundation.abide.js b/js/foundation.abide.js index cd1aca349..6bf27f507 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -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 diff --git a/test/javascript/components/abide.js b/test/javascript/components/abide.js index 19ea148db..c49ee1ae8 100644 --- a/test/javascript/components/abide.js +++ b/test/javascript/components/abide.js @@ -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 error +
+ `).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 = $(`
-- 2.47.2