From d1acd32dc725ac0b9846605fa4a5f09403144a52 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Tue, 16 Jan 2018 23:27:14 +0100 Subject: [PATCH] feat: add `a11yAttributes` option on Abide to disable a11y attribute insertion --- js/foundation.abide.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 1b6b924e4..e7da57790 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -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(); } @@ -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')); }); @@ -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. -- 2.47.2