]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Merge branch 'off-canvas-overlay-tweaks' into Owlbertz-keyboard-enhancements-v6.3
authorKevin Ball <kmball11@gmail.com>
Thu, 1 Dec 2016 20:31:15 +0000 (12:31 -0800)
committerKevin Ball <kmball11@gmail.com>
Thu, 1 Dec 2016 20:31:15 +0000 (12:31 -0800)
1  2 
js/foundation.offcanvas.js
test/javascript/components/offcanvas.js

index 97e61410b447d829fb0e9c7f652d086d0e14ddca,54119a27ccec23ee27e5bebc17182a41d06c1aaa..8b67e4f186953d7f2932f20e7f66937c05ab3369
@@@ -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);
      }
    }
  
      }
  
      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);
      }
    }
  
index 3e940169e068ef771144be8d8acb629f3da63b77,4dcce0e903360115da9f47e38b87e0096cfc3b05..f4f297429699579160f3c1bfb75c062a6e22da12
@@@ -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();
        });
  
        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');
        $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
        $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();
          });