From: Daniel Ruf Date: Tue, 13 Mar 2018 20:54:41 +0000 (+0100) Subject: fix: add aria-expanded to the toggler triggers X-Git-Tag: v6.6.0~3^2~277^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbc69f10e;p=thirdparty%2Ffoundation%2Ffoundation-sites.git fix: add aria-expanded to the toggler triggers --- diff --git a/js/foundation.toggler.js b/js/foundation.toggler.js index d8c5744ec..65effcbbe 100644 --- a/js/foundation.toggler.js +++ b/js/foundation.toggler.js @@ -58,9 +58,10 @@ class Toggler extends Plugin { // Add ARIA attributes to triggers var id = this.$element[0].id; $(`[data-open="${id}"], [data-close="${id}"], [data-toggle="${id}"]`) - .attr('aria-controls', id); - // If the target is hidden, add aria-hidden - this.$element.attr('aria-expanded', this.$element.is(':hidden') ? false : true); + .attr({ + 'aria-controls': id, + 'aria-expanded': this.$element.is(':hidden') ? false : true + }); } /** diff --git a/test/javascript/components/toggler.js b/test/javascript/components/toggler.js index e55817b37..322bf9e3e 100644 --- a/test/javascript/components/toggler.js +++ b/test/javascript/components/toggler.js @@ -58,17 +58,31 @@ describe('Toggler', function() { it('sets aria-expanded to true if the element is visible', function() { $html = $('
').appendTo('body'); + var $triggers = $(`
+ Open + Close + Toggle +
`).appendTo('body'); plugin = new Foundation.Toggler($html, {}); - $('#toggler').should.have.attr('aria-expanded', 'true'); + $triggers.find('[data-open]').should.have.attr('aria-expanded', 'true'); + $triggers.find('[data-close]').should.have.attr('aria-expanded', 'true'); + $triggers.find('[data-open]').should.have.attr('aria-expanded', 'true'); }); it('sets aria-expanded to false if the element is invisible', function() { var $css = $('').appendTo('body'); $html = $('
').appendTo('body'); + var $triggers = $(`
+ Open + Close + Toggle +
`).appendTo('body'); plugin = new Foundation.Toggler($html, {}); - $('#toggler').should.have.attr('aria-expanded', 'false'); + $triggers.find('[data-open]').should.have.attr('aria-expanded', 'false'); + $triggers.find('[data-close]').should.have.attr('aria-expanded', 'false'); + $triggers.find('[data-open]').should.have.attr('aria-expanded', 'false'); $css.remove(); }); });