From ef6fa09f02009b8def6d8aff6b394c59867cdeaa Mon Sep 17 00:00:00 2001 From: Pavel Pomerantsev Date: Wed, 18 Mar 2015 15:50:02 +0300 Subject: [PATCH] fix(ngTouch): prevent touchmove from canceling a click Usually browsers fire touchstart and touchend, and ng-click works. But some browsers (I only experienced it on iOS) fire touchmove between touchstart and touchend, and so before this fix ng-click would not work in this case. Also, the test for touchmove was incorrect: it did not test the touchmove event itself, but rather the coordinates change, which is handled elsewhere. If the coordinates are the same and the interval is not too long, ng-click should fire, no matter if there was a touchmove or not. --- src/ngTouch/directive/ngClick.js | 4 ---- test/ngTouch/directive/ngClickSpec.js | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ngTouch/directive/ngClick.js b/src/ngTouch/directive/ngClick.js index 90274aba7322..e28d4a6a032c 100644 --- a/src/ngTouch/directive/ngClick.js +++ b/src/ngTouch/directive/ngClick.js @@ -227,10 +227,6 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', touchStartY = e.clientY; }); - element.on('touchmove', function(event) { - resetState(); - }); - element.on('touchcancel', function(event) { resetState(); }); diff --git a/test/ngTouch/directive/ngClickSpec.js b/test/ngTouch/directive/ngClickSpec.js index 921c64578b2b..543ff69cd9b9 100644 --- a/test/ngTouch/directive/ngClickSpec.js +++ b/test/ngTouch/directive/ngClickSpec.js @@ -97,7 +97,7 @@ describe('ngClick (touch)', function() { })); - it('should not click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) { + it('should still click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) { element = $compile('
')($rootScope); $rootElement.append(element); $rootScope.$digest(); @@ -112,11 +112,11 @@ describe('ngClick (touch)', function() { browserTrigger(element, 'touchmove'); browserTrigger(element, 'touchend',{ keys: [], - x: 400, - y: 400 + x: 10, + y: 10 }); - expect($rootScope.tapped).toBeUndefined(); + expect($rootScope.tapped).toBe(true); })); it('should add the CSS class while the element is held down, and then remove it', inject(function($rootScope, $compile, $rootElement) {