From 5ddb04b6e216e6bfd5291bcf85b1c9de55b2d89d Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Thu, 1 Nov 2018 23:59:58 +0100 Subject: [PATCH] fix: ensure Dropdown aria-labelledby to have an ID #11572 Closes https://github.com/zurb/foundation-sites/issues/11572 --- js/foundation.dropdown.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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(); -- 2.47.2