From 07b2d7670645cf1bf47f0028fc711af73c503d78 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Tue, 16 Jan 2018 22:17:53 +0100 Subject: [PATCH] feat: add [aria-live] on [data-abide-error] on form validation Add Abide option: `globalErrorAriaLevel` --- js/foundation.abide.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 2b1728758..74d572e88 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -344,7 +344,11 @@ class Abide extends Plugin { var noError = acc.indexOf(false) === -1; - this.$element.find('[data-abide-error]').css('display', (noError ? 'none' : 'block')); + this.$element.find('[data-abide-error]').each((i, elem) => { + const $elem = $(elem); + $elem.attr('aria-live', $elem.attr('data-aria-level') || this.options.globalErrorAriaLevel); + $elem.css('display', (noError ? 'none' : 'block')); + }); /** * Fires when the form is finished validating. Event trigger is either `formvalid.zf.abide` or `forminvalid.zf.abide`. @@ -532,6 +536,16 @@ Abide.defaults = { */ formErrorClass: 'is-visible', + /** + * Aria-live level 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', + /** * Set to true to validate text inputs on any value change. * @option -- 2.47.2