Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7c31b19

Browse files
committed
fix(ngTouch): don't prevent click event after a touchmove
Remove the touchmove handler so that resetState is not called on touchmove. The touchend event handler already prevents the click from being triggered if the distance moved exceeds the MOVE_TOLERANCE, so detection of touchmove is not needed. Previously, because of resetState on touchmove, the click would not be triggered even if the event coordinates changed by only 1px or 2px, which seems to be very common for taps on mobile browsers.
1 parent 28114fa commit 7c31b19

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/ngTouch/directive/ngClick.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
6666
// double-tapping, and then fire a click event.
6767
//
6868
// This delay sucks and makes mobile apps feel unresponsive.
69-
// So we detect touchstart, touchmove, touchcancel and touchend ourselves and determine when
69+
// So we detect touchstart, touchcancel and touchend ourselves and determine when
7070
// the user has tapped on something.
7171
//
7272
// What happens when the browser then generates a click event?
@@ -78,7 +78,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
7878
// So the sequence for a tap is:
7979
// - global touchstart: Sets an "allowable region" at the point touched.
8080
// - element's touchstart: Starts a touch
81-
// (- touchmove or touchcancel ends the touch, no click follows)
81+
// (- touchcancel ends the touch, no click follows)
8282
// - element's touchend: Determines if the tap is valid (didn't move too far away, didn't hold
8383
// too long) and fires the user's tap handler. The touchend also calls preventGhostClick().
8484
// - preventGhostClick() removes the allowable region the global touchstart created.
@@ -227,10 +227,6 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
227227
touchStartY = e.clientY;
228228
});
229229

230-
element.on('touchmove', function(event) {
231-
resetState();
232-
});
233-
234230
element.on('touchcancel', function(event) {
235231
resetState();
236232
});

test/ngTouch/directive/ngClickSpec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('ngClick (touch)', function() {
9797
}));
9898

9999

100-
it('should not click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) {
100+
it('should not prevent click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) {
101101
element = $compile('<div ng-click="tapped = true"></div>')($rootScope);
102102
$rootElement.append(element);
103103
$rootScope.$digest();
@@ -112,11 +112,11 @@ describe('ngClick (touch)', function() {
112112
browserTrigger(element, 'touchmove');
113113
browserTrigger(element, 'touchend',{
114114
keys: [],
115-
x: 400,
116-
y: 400
115+
x: 15,
116+
y: 15
117117
});
118118

119-
expect($rootScope.tapped).toBeUndefined();
119+
expect($rootScope.tapped).toEqual(true);
120120
}));
121121

122122
it('should add the CSS class while the element is held down, and then remove it', inject(function($rootScope, $compile, $rootElement) {

0 commit comments

Comments
 (0)