From e84e7d119639639fa0bad52af268f005dea06595 Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Tue, 13 Mar 2018 23:18:33 +0100 Subject: [PATCH] fix: apply aria-expanded to the toggler triggers in _updateARIA --- js/foundation.toggler.js | 6 ++++- test/javascript/components/toggler.js | 33 +++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/js/foundation.toggler.js b/js/foundation.toggler.js index 65effcbbe..6427e2c95 100644 --- a/js/foundation.toggler.js +++ b/js/foundation.toggler.js @@ -126,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 322bf9e3e..65c6ed77f 100644 --- a/test/javascript/components/toggler.js +++ b/test/javascript/components/toggler.js @@ -106,13 +106,22 @@ describe('Toggler', function() { it('updates aria-expanded after the class is toggled', function() { $html = $('
').appendTo('body'); + var $triggers = $(`
+ Open + Close + Toggle +
`).appendTo('body'); plugin = new Foundation.Toggler($html, {}); plugin._toggleClass(); - $('#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'); plugin._toggleClass(); - $('#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'); }); }); @@ -121,11 +130,19 @@ describe('Toggler', function() { it('animates an invisible element in', function(done) { var $css = $('').appendTo('body'); $html = $('
').appendTo('body'); + var $triggers = $(`
+ Open + Close + Toggle +
`).appendTo('body'); + plugin = new Foundation.Toggler($html, {}); $html.on('on.zf.toggler', function() { $('#toggler').should.be.visible; - $('#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'); $css.remove(); done(); }); @@ -135,11 +152,19 @@ describe('Toggler', function() { it('animates an visible element out', function(done) { $html = $('
').appendTo('body'); + var $triggers = $(`
+ Open + Close + Toggle +
`).appendTo('body'); + plugin = new Foundation.Toggler($html, {}); $html.on('off.zf.toggler', function() { $('#toggler').should.be.hidden; - $('#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'); done(); }); -- 2.47.3