From: Kevin Ball Date: Thu, 1 Dec 2016 20:31:15 +0000 (-0800) Subject: Merge branch 'off-canvas-overlay-tweaks' into Owlbertz-keyboard-enhancements-v6.3 X-Git-Tag: v6.3-rc1~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4f4b5cbd2e49a809e17b7c56a7c6ed8c4681c3c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Merge branch 'off-canvas-overlay-tweaks' into Owlbertz-keyboard-enhancements-v6.3 --- a4f4b5cbd2e49a809e17b7c56a7c6ed8c4681c3c diff --cc js/foundation.offcanvas.js index 97e61410b,54119a27c..8b67e4f18 --- a/js/foundation.offcanvas.js +++ b/js/foundation.offcanvas.js @@@ -200,8 -200,8 +200,8 @@@ class OffCanvas } if (this.options.trapFocus === true) { - $('[data-off-canvas-content]').attr('tabindex', '-1'); + this.$elements.siblings('[data-off-canvas-content]').attr('tabindex', '-1'); - this._trapFocus(); + Foundation.Keyboard.trapFocus(_this.$element); } } @@@ -239,10 -261,8 +239,10 @@@ } this.$triggers.attr('aria-expanded', 'false'); + if (this.options.trapFocus === true) { - $('[data-off-canvas-content]').removeAttr('tabindex'); + this.$element.siblings('[data-off-canvas-content]').removeAttr('tabindex'); + Foundation.Keyboard.releaseFocus(this.$element); } } diff --cc test/javascript/components/offcanvas.js index 3e940169e,4dcce0e90..f4f297429 --- a/test/javascript/components/offcanvas.js +++ b/test/javascript/components/offcanvas.js @@@ -98,10 -99,12 +99,12 @@@ describe('Off Canvas', function() $html = $(template).appendTo('body'); plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {}); - $html.one(Foundation.transitionend($html), function() { - plugin.$element.should.have.class('is-open'); - $html.find('[data-off-canvas-wrapper]').should.have.class('is-off-canvas-open'); - done(); + $html.one('opened.zf.offcanvas', function() { - setTimeout(function() { ++ setTimeout(function() { + plugin.$element.should.have.class('is-open'); + $('body').should.have.class('is-off-canvas-open'); + done(); + }, 1); }); plugin.open(); @@@ -131,23 -123,10 +123,25 @@@ }); plugin.open(); + // fake transitionend for console tests + plugin.$element.triggerHandler(Foundation.transitionend(plugin.$element)); }); + it('traps focus if trapFocus option is true', function(done) { + $html = $(template).appendTo('body'); + plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {trapFocus: true}); + + let spy = sinon.spy(Foundation.Keyboard, 'trapFocus'); + + $html.one(Foundation.transitionend($html), function() { + sinon.assert.called(spy); + Foundation.Keyboard.trapFocus.restore(); + done(); + }); + + plugin.open(); + }); + it('fires opened.zf.offcanvas event', function(done) { $html = $(template).appendTo('body'); @@@ -184,12 -161,14 +176,14 @@@ $html = $(template).appendTo('body'); plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {}); - $html.one(Foundation.transitionend($html), function() { - plugin.close(); + $html.one('opened.zf.offcanvas', function() { - setTimeout(function() { ++ setTimeout(function() { + plugin.close(); - plugin.$element.should.not.have.class('is-open'); - $html.find('[data-off-canvas-wrapper]').should.not.have.class('is-off-canvas-open'); - done(); + plugin.$element.should.not.have.class('is-open'); + $('body').should.not.have.class('is-off-canvas-open'); + done(); + }, 1); }); // Open it first @@@ -200,7 -179,9 +194,7 @@@ $html = $(template).appendTo('body'); plugin = new Foundation.OffCanvas($html.find('[data-off-canvas]'), {}); - $html.one(Foundation.transitionend($html), function() { - - + $html.one('opened.zf.offcanvas', function() { $html.one('closed.zf.offcanvas', function() { done(); });