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

Commit e034024

Browse files
revolunetIgorMinar
authored andcommittedJul 24, 2013
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
1 parent 52b8211 commit e034024

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed
 

‎src/ngMobile/directive/ngClick.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,11 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement',
232232
tapElement.blur();
233233
}
234234

235-
scope.$apply(function() {
236-
// TODO(braden): This is sending the touchend, not a tap or click. Is that kosher?
237-
clickHandler(scope, {$event: event});
238-
});
235+
if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
236+
scope.$apply(function() {
237+
clickHandler(scope, {$event: event});
238+
});
239+
}
239240
}
240241

241242
resetState();

‎test/ngMobile/directive/ngClickSpec.js

+48
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,52 @@ describe('ngClick (mobile)', function() {
310310
});
311311

312312

313+
describe('disabled state', function() {
314+
it('should not trigger click if ngDisabled is true', inject(function($rootScope, $compile) {
315+
element = $compile('<div ng-click="event = $event" ng-disabled="disabled"></div>')($rootScope);
316+
$rootScope.disabled = true;
317+
$rootScope.$digest();
318+
319+
browserTrigger(element, 'touchstart', [], 10, 10);
320+
browserTrigger(element, 'touchend', [], 10, 10);
321+
322+
expect($rootScope.event).toBeUndefined();
323+
}));
324+
it('should trigger click if ngDisabled is false', inject(function($rootScope, $compile) {
325+
element = $compile('<div ng-click="event = $event" ng-disabled="disabled"></div>')($rootScope);
326+
$rootScope.disabled = false;
327+
$rootScope.$digest();
328+
329+
browserTrigger(element, 'touchstart', [], 10, 10);
330+
browserTrigger(element, 'touchend', [], 10, 10);
331+
332+
expect($rootScope.event).toBeDefined();
333+
}));
334+
it('should not trigger click if regular disabled is true', inject(function($rootScope, $compile) {
335+
element = $compile('<div ng-click="event = $event" disabled="true"></div>')($rootScope);
336+
337+
browserTrigger(element, 'touchstart', [], 10, 10);
338+
browserTrigger(element, 'touchend', [], 10, 10);
339+
340+
expect($rootScope.event).toBeUndefined();
341+
}));
342+
it('should not trigger click if regular disabled is present', inject(function($rootScope, $compile) {
343+
element = $compile('<button ng-click="event = $event" disabled ></button>')($rootScope);
344+
345+
browserTrigger(element, 'touchstart', [], 10, 10);
346+
browserTrigger(element, 'touchend', [], 10, 10);
347+
348+
expect($rootScope.event).toBeUndefined();
349+
}));
350+
it('should trigger click if regular disabled is not present', inject(function($rootScope, $compile) {
351+
element = $compile('<div ng-click="event = $event" ></div>')($rootScope);
352+
353+
browserTrigger(element, 'touchstart', [], 10, 10);
354+
browserTrigger(element, 'touchend', [], 10, 10);
355+
356+
expect($rootScope.event).toBeDefined();
357+
}));
358+
});
359+
360+
313361
});

0 commit comments

Comments
 (0)
This repository has been archived.