From c6e4b562c60898ec39713b806153b8dcc0979010 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Mon, 22 Jan 2018 23:31:40 +0100 Subject: [PATCH] feat: add [role=label] to all form errors in Abide --- js/foundation.abide.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 28ef56d47..b307f29a5 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -207,7 +207,7 @@ class Abide extends Plugin { } /** - * Adds [for] attributes to all form error targetting $el, + * Adds [for] and [role=alert] attributes to all form error targetting $el, * and [aria-describedby] attribute to $el toward the first form error. * @param {Object} $el - jQuery object */ @@ -244,6 +244,13 @@ class Abide extends Plugin { $label.attr('for', elemId); }).end(); } + + // For each error targeting $el, set [role=alert] if it is not set. + $errors.each((i, label) => { + const $label = $(label); + if (typeof $label.attr('role') === 'undefined') + $label.attr('role', 'alert'); + }).end(); } /** @@ -595,8 +602,10 @@ Abide.defaults = { formErrorClass: 'is-visible', /** - * 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`). + * If true, automatically insert when possible: + * - `[aria-describedby]` on fields + * - `[role=alert]` on form errors and `[for]` on form error labels + * - `[aria-live]` on global errors `[data-abide-error]` (see option `a11yErrorLevel`). * @option * @type {boolean} * @default true -- 2.47.2