Skip to content

Commit

Permalink
reset carousel touch delta x to prevent click transformed in swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Mar 26, 2019
1 parent d7ecff2 commit e883652
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions js/src/carousel.js
Expand Up @@ -257,6 +257,8 @@ class Carousel {

const direction = absDeltax / this.touchDeltaX

this.touchDeltaX = 0

// swipe left
if (direction > 0) {
this.prev()
Expand Down
6 changes: 4 additions & 2 deletions js/tests/unit/carousel.js
Expand Up @@ -1153,7 +1153,7 @@ $(function () {
}

document.documentElement.ontouchstart = $.noop
assert.expect(3)
assert.expect(4)
Simulator.setType('pointer')

var $styles = $(stylesCarousel).appendTo('head')
Expand Down Expand Up @@ -1182,6 +1182,7 @@ $(function () {
assert.ok(true, 'slid event fired')
assert.ok(!$item.hasClass('active'))
assert.ok(spy.called)
assert.strictEqual(carousel.touchDeltaX, 0)
$styles.remove()
delete document.documentElement.ontouchstart
done()
Expand All @@ -1195,7 +1196,7 @@ $(function () {
})

QUnit.test('should allow swipeleft and call next with touch events', function (assert) {
assert.expect(3)
assert.expect(4)
clearPointerEvents()
Simulator.setType('touch')
document.documentElement.ontouchstart = $.noop
Expand Down Expand Up @@ -1225,6 +1226,7 @@ $(function () {
assert.ok(true, 'slid event fired')
assert.ok(!$item.hasClass('active'))
assert.ok(spy.called)
assert.strictEqual(carousel.touchDeltaX, 0)
restorePointerEvents()
delete document.documentElement.ontouchstart
done()
Expand Down

0 comments on commit e883652

Please sign in to comment.