Skip to content

Commit

Permalink
feat: add a11yAttributes option on Abide to disable a11y attribute …
Browse files Browse the repository at this point in the history
…insertion
  • Loading branch information
ncoden committed Jan 16, 2018
1 parent 88abca7 commit d1acd32
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions js/foundation.abide.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Abide extends Plugin {
this.$inputs = this.$element.find('input, textarea, select');

// Add a11y attributes to all fields
this.$inputs.each((i, input) => {
this.addA11yAttributes($(input));
});
if (this.options.a11yAttributes) {
this.$inputs.each((i, input) => this.addA11yAttributes($(input)));
}

this._events();
}
Expand Down Expand Up @@ -392,7 +392,9 @@ class Abide extends Plugin {

this.$element.find('[data-abide-error]').each((i, elem) => {
const $elem = $(elem);
$elem.attr('aria-live', $elem.attr('data-aria-level') || this.options.globalErrorAriaLevel);
if (this.options.a11yAttributes) {
$elem.attr('aria-live', $elem.attr('data-aria-level') || this.options.a11yErrorLevel);
}
$elem.css('display', (noError ? 'none' : 'block'));
});

Expand Down Expand Up @@ -583,14 +585,23 @@ Abide.defaults = {
formErrorClass: 'is-visible',

/**
* Aria-live level to be applied on global errors `[data-abide-error]`.
* If true, automatically insert when possible `[aria-describedby]` on fields, `[for]` on label
* and [aria-live] on global errors `[data-abide-error]` (see option `a11yErrorLevel`).
* @option
* @type {boolean}
* @default true
*/
a11yAttributes: true,

/**
* [aria-live] attribute value to be applied on global errors `[data-abide-error]`.
* Options are: 'assertive', 'polite' and 'off'/null
* @option
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
* @type {string}
* @default 'assertive'
*/
globalErrorAriaLevel: 'assertive',
a11yErrorLevel: 'assertive',

/**
* Set to true to validate text inputs on any value change.
Expand Down

0 comments on commit d1acd32

Please sign in to comment.