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

Commit 9552187

Browse files
mikecpetebacondarwin
authored andcommitted
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. Closes #10985
1 parent 4eb16ae commit 9552187

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/ngTouch/directive/ngClick.js

+2-6
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.
@@ -229,10 +229,6 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
229229
touchStartY = e.clientY;
230230
});
231231

232-
element.on('touchmove', function(event) {
233-
resetState();
234-
});
235-
236232
element.on('touchcancel', function(event) {
237233
resetState();
238234
});

test/ngTouch/directive/ngClickSpec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('ngClick (touch)', function() {
125125
}));
126126

127127

128-
it('should not click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) {
128+
it('should not prevent click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) {
129129
element = $compile('<div ng-click="tapped = true"></div>')($rootScope);
130130
$rootElement.append(element);
131131
$rootScope.$digest();
@@ -140,11 +140,11 @@ describe('ngClick (touch)', function() {
140140
browserTrigger(element, 'touchmove');
141141
browserTrigger(element, 'touchend',{
142142
keys: [],
143-
x: 400,
144-
y: 400
143+
x: 15,
144+
y: 15
145145
});
146146

147-
expect($rootScope.tapped).toBeUndefined();
147+
expect($rootScope.tapped).toEqual(true);
148148
}));
149149

150150
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)