Skip to content

Commit

Permalink
fix: Don't toggle when panning while disabled (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolmaus authored and knownasilya committed Sep 12, 2017
1 parent 9863f33 commit 95d839a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions addon/components/x-toggle-switch/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ export default Component.extend(RecognizerMixin, {
}),

panRight() {
if (this.get('disabled')) {
return;
}

this.get('sendToggle')(true);
this._disableLabelUntilMouseUp()
},

panLeft() {
if (this.get('disabled')) {
return;
}

this.get('sendToggle')(false);
this._disableLabelUntilMouseUp();
},
Expand Down
19 changes: 17 additions & 2 deletions tests/integration/components/x-toggle/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,24 @@ if (emberVersionGTE(2, 0)) {
const $toggle = this.$('.x-toggle-container');

$toggle.trigger('panright');
assert.equal(this.get('value'), true, 'swiping right should enable');
assert.equal(this.get('value'), true, 'panning right should enable');

$toggle.trigger('panleft');
assert.equal(this.get('value'), false, 'swiping left should disable');
assert.equal(this.get('value'), false, 'panning left should disable');
});

test('swipe gesture while disabled', function(assert) {
this.set('value', false);

this.render(hbs`{{x-toggle
disabled=true
value=value
onToggle=(action (mut value))
}}`);

const $toggle = this.$('.x-toggle-container');

$toggle.trigger('panright');
assert.equal(this.get('value'), false, 'panning right should not enable');
});
}

0 comments on commit 95d839a

Please sign in to comment.