From: Stefan Lisper Date: Sat, 16 Jun 2018 07:56:01 +0000 (+0200) Subject: Use pull request #11167 from MoarCoding/develop for v6.5.0 X-Git-Tag: v6.5.0-rc.1^2~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce513bc776f9ca11f4ca8914e923ecb75eff16aa;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #11167 from MoarCoding/develop for v6.5.0 2bfd3e0c4 fixed bug where aria-controls is not updated with multiple ids 3e6e35cb6 Removed old code 6437acf2b fix: improve id detection/replacment for Toggler `aria-controls` attribute Co-Authored-By: Nicolas Coden Signed-off-by: Nicolas Coden --- diff --git a/js/foundation.toggler.js b/js/foundation.toggler.js index 5373cecb4..f1f67930c 100644 --- a/js/foundation.toggler.js +++ b/js/foundation.toggler.js @@ -3,6 +3,7 @@ import $ from 'jquery'; import { Motion } from './foundation.util.motion'; import { Plugin } from './foundation.core.plugin'; +import { RegExpEscape } from './foundation.core.utils'; import { Triggers } from './foundation.util.triggers'; /** @@ -55,13 +56,20 @@ class Toggler extends Plugin { this.className = input[0] === '.' ? input.slice(1) : input; } - // Add ARIA attributes to triggers - var id = this.$element[0].id; - $(`[data-open="${id}"], [data-close="${id}"], [data-toggle="${id}"]`) - .attr({ - 'aria-controls': id, - 'aria-expanded': this.$element.is(':hidden') ? false : true - }); + // Add ARIA attributes to triggers: + var id = this.$element[0].id, + $triggers = $(`[data-open~="${id}"], [data-close~="${id}"], [data-toggle~="${id}"]`); + + // - aria-expanded: according to the element visibility. + $triggers.attr('aria-expanded', !this.$element.is(':hidden')); + // - aria-controls: adding the element id to it if not already in it. + $triggers.each((index, trigger) => { + const $trigger = $(trigger); + const controls = $trigger.attr('aria-controls') || ''; + + const containsId = new RegExp(`\\b${RegExpEscape(id)}\\b`).test(controls); + if (!containsId) $trigger.attr('aria-controls', controls ? `${controls} ${id}` : id); + }); } /**