}
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);
}
}
$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();
});