aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Bouquillon2013-07-05 02:07:12 +0200
committerIgor Minar2013-07-24 16:58:12 -0700
commite03402433d2524fd3a74bbfce984f843794996ce (patch)
treedd119074f98f1b476b373aee88b1df0176fecbca
parent52b8211fd0154b9d6b771a83573a161f5580d92c (diff)
downloadangular.js-e03402433d2524fd3a74bbfce984f843794996ce.tar.bz2
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 Closes #3124 Closes #3132
-rw-r--r--src/ngMobile/directive/ngClick.js9
-rw-r--r--test/ngMobile/directive/ngClickSpec.js48
2 files changed, 53 insertions, 4 deletions
diff --git a/src/ngMobile/directive/ngClick.js b/src/ngMobile/directive/ngClick.js
index 3fa68cb4..358a1af9 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 dd7ffed0..1147f0a2 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('<div ng-click="event = $event" ng-disabled="disabled"></div>')($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('<div ng-click="event = $event" ng-disabled="disabled"></div>')($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('<div ng-click="event = $event" disabled="true"></div>')($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('<button ng-click="event = $event" disabled ></button>')($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('<div ng-click="event = $event" ></div>')($rootScope);
+
+ browserTrigger(element, 'touchstart', [], 10, 10);
+ browserTrigger(element, 'touchend', [], 10, 10);
+
+ expect($rootScope.event).toBeDefined();
+ }));
+ });
+
+
});