Skip to content

Commit

Permalink
Merge pull request #12496 from ahukkanen/fix/hidden-input-aria-descri…
Browse files Browse the repository at this point in the history
…bedby

fix: do not add aria-describedby to hidden inputs
  • Loading branch information
joeworkman authored Sep 27, 2024
2 parents 570374b + dff781f commit 3ea67b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/foundation.abide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/javascript/components/abide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 3ea67b0

Please sign in to comment.