From: Nicolas Coden Date: Thu, 1 Nov 2018 22:59:58 +0000 (+0100) Subject: fix: ensure Dropdown aria-labelledby to have an ID #11572 X-Git-Tag: v6.6.0~3^2~67^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ddb04b6e;p=thirdparty%2Ffoundation%2Ffoundation-sites.git fix: ensure Dropdown aria-labelledby to have an ID #11572 Closes https://github.com/zurb/foundation-sites/issues/11572 --- diff --git a/js/foundation.dropdown.js b/js/foundation.dropdown.js index 261490322..d12f02a61 100644 --- a/js/foundation.dropdown.js +++ b/js/foundation.dropdown.js @@ -68,16 +68,20 @@ class Dropdown extends Positionable { this.$parent = null; } - // Do not change the `labelledby` if it is defined - var labelledby = this.$element.attr('aria-labelledby') - || this.$currentAnchor.attr('id') - || GetYoDigits(6, 'dd-anchor'); + // Set [aria-describedby] on the Dropdown if it is not set + if (typeof this.$element.attr('aria-describedby') === 'undefined') { + // Get the anchor ID or create one + if (typeof this.$currentAnchor.attr('id') === 'undefined') { + this.$currentAnchor.attr('id', GetYoDigits(6, 'dd-anchor')); + }; + + this.$element.attr('aria-labelledby', this.$currentAnchor.attr('id')); + } this.$element.attr({ 'aria-hidden': 'true', 'data-yeti-box': $id, 'data-resize': $id, - 'aria-labelledby': labelledby }); super._init();