From: Daniel Ruf Date: Sat, 16 Jun 2018 07:27:59 +0000 (+0200) Subject: Use pull request #11052 from DanielRuf/fix/toggler-aria-expanded-on-trigger-11049... X-Git-Tag: v6.5.0-rc.1^2~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca8a1afc9c31a2038c739b9a06a612240e3e9ff7;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #11052 from DanielRuf/fix/toggler-aria-expanded-on-trigger-11049 for v6.5.0 fbc69f10e fix: add aria-expanded to the toggler triggers e84e7d119 fix: apply aria-expanded to the toggler triggers in _updateARIA dd96a42ad tests: replace duplicate code in the toggler test Signed-off-by: Nicolas Coden --- diff --git a/js/foundation.toggler.js b/js/foundation.toggler.js index d8c5744ec..6427e2c95 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 + }); } /** @@ -125,7 +126,11 @@ class Toggler extends Plugin { } _updateARIA(isOn) { - this.$element.attr('aria-expanded', isOn ? true : false); + var id = this.$element[0].id; + $(`[data-open="${id}"], [data-close="${id}"], [data-toggle="${id}"]`) + .attr({ + 'aria-expanded': isOn ? true : false + }); } /** diff --git a/test/javascript/components/toggler.js b/test/javascript/components/toggler.js index e55817b37..7d9010795 100644 --- a/test/javascript/components/toggler.js +++ b/test/javascript/components/toggler.js @@ -7,6 +7,14 @@ describe('Toggler', function() { $html.remove(); }); + function appendTriggers() { + return $(`
+ Open + Close + Toggle +
`).appendTo('body') + } + describe('constructor()', function() { it('stores the element and plugin options', function() { $html = $('
').appendTo('body'); @@ -42,33 +50,29 @@ describe('Toggler', function() { it('adds Aria attributes to click triggers', function() { $html = $('
').appendTo('body'); - var $triggers = $(`
- Open - Close - Toggle -
`).appendTo('body'); + var $triggers = appendTriggers(); plugin = new Foundation.Toggler($html, {}); - $triggers.find('[data-open]').should.have.attr('aria-controls', 'toggler'); - $triggers.find('[data-close]').should.have.attr('aria-controls', 'toggler'); - $triggers.find('[data-toggle]').should.have.attr('aria-controls', 'toggler'); + $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-controls', 'toggler'); $triggers.remove(); }); it('sets aria-expanded to true if the element is visible', function() { $html = $('
').appendTo('body'); + var $triggers = appendTriggers(); plugin = new Foundation.Toggler($html, {}); - $('#toggler').should.have.attr('aria-expanded', 'true'); + $triggers.find('[data-open], [data-close], [data-toggle]').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 = appendTriggers(); plugin = new Foundation.Toggler($html, {}); - $('#toggler').should.have.attr('aria-expanded', 'false'); + $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'false'); $css.remove(); }); }); @@ -92,13 +96,14 @@ describe('Toggler', function() { it('updates aria-expanded after the class is toggled', function() { $html = $('
').appendTo('body'); + var $triggers = appendTriggers(); plugin = new Foundation.Toggler($html, {}); plugin._toggleClass(); - $('#toggler').should.have.attr('aria-expanded', 'true'); + $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'true'); plugin._toggleClass(); - $('#toggler').should.have.attr('aria-expanded', 'false'); + $triggers.find('[data-open], [data-close], [data-toggle]').should.have.attr('aria-expanded', 'false'); }); }); @@ -107,11 +112,11 @@ describe('Toggler', function() { it('animates an invisible element in', function(done) { var $css = $('').appendTo('body'); $html = $('
').appendTo('body'); + plugin = new Foundation.Toggler($html, {}); $html.on('on.zf.toggler', function() { $('#toggler').should.be.visible; - $('#toggler').should.have.attr('aria-expanded', 'true'); $css.remove(); done(); }); @@ -119,13 +124,13 @@ describe('Toggler', function() { plugin._toggleAnimate(); }); - it('animates an visible element out', function(done) { + it('animates a visible element out', function(done) { $html = $('
').appendTo('body'); + plugin = new Foundation.Toggler($html, {}); $html.on('off.zf.toggler', function() { $('#toggler').should.be.hidden; - $('#toggler').should.have.attr('aria-expanded', 'false'); done(); });