From a3955aeb5e333fca3a6dffc08ac798800e25d694 Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Fri, 5 Jul 2013 02:07:12 +0200 Subject: [PATCH] fix(ngMobile): prevent ngClick when item disabled - the ngClick attribute was always triggered, regardless the ngDisabled/disabled attributes - we now check the DOM disabled status before triggering the original click event - deals with #3124 #3132 /cc @shepheb --- src/ngMobile/directive/ngClick.js | 9 ++--- test/ngMobile/directive/ngClickSpec.js | 48 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/ngMobile/directive/ngClick.js b/src/ngMobile/directive/ngClick.js index 3fa68cb4b75f..358a1af9056d 100644 --- a/src/ngMobile/directive/ngClick.js +++ b/src/ngMobile/directive/ngClick.js @@ -232,10 +232,11 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement', tapElement.blur(); } - scope.$apply(function() { - // TODO(braden): This is sending the touchend, not a tap or click. Is that kosher? - clickHandler(scope, {$event: event}); - }); + if (!angular.isDefined(attr.disabled) || attr.disabled === false) { + scope.$apply(function() { + clickHandler(scope, {$event: event}); + }); + } } resetState(); diff --git a/test/ngMobile/directive/ngClickSpec.js b/test/ngMobile/directive/ngClickSpec.js index dd7ffed00fe8..1147f0a20d2f 100644 --- a/test/ngMobile/directive/ngClickSpec.js +++ b/test/ngMobile/directive/ngClickSpec.js @@ -310,4 +310,52 @@ describe('ngClick (mobile)', function() { }); + describe('disabled state', function() { + it('should not trigger click if ngDisabled is true', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + $rootScope.disabled = true; + $rootScope.$digest(); + + browserTrigger(element, 'touchstart', [], 10, 10); + browserTrigger(element, 'touchend', [], 10, 10); + + expect($rootScope.event).toBeUndefined(); + })); + it('should trigger click if ngDisabled is false', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + $rootScope.disabled = false; + $rootScope.$digest(); + + browserTrigger(element, 'touchstart', [], 10, 10); + browserTrigger(element, 'touchend', [], 10, 10); + + expect($rootScope.event).toBeDefined(); + })); + it('should not trigger click if regular disabled is true', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + + browserTrigger(element, 'touchstart', [], 10, 10); + browserTrigger(element, 'touchend', [], 10, 10); + + expect($rootScope.event).toBeUndefined(); + })); + it('should not trigger click if regular disabled is present', inject(function($rootScope, $compile) { + element = $compile('')($rootScope); + + browserTrigger(element, 'touchstart', [], 10, 10); + browserTrigger(element, 'touchend', [], 10, 10); + + expect($rootScope.event).toBeUndefined(); + })); + it('should trigger click if regular disabled is not present', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + + browserTrigger(element, 'touchstart', [], 10, 10); + browserTrigger(element, 'touchend', [], 10, 10); + + expect($rootScope.event).toBeDefined(); + })); + }); + + });