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

Commit 69a0d8b

Browse files
busiqmmalerba
authored andcommitted
fix(checkbox): click handling when ngCheckbox is set (#10468) (#10472)
1 parent 0f3ef64 commit 69a0d8b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/components/checkbox/checkbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
184184

185185
scope.$apply(function() {
186186
// Toggle the checkbox value...
187-
var viewValue = attr.ngChecked ? attr.checked : !ngModelCtrl.$viewValue;
187+
var viewValue = attr.ngChecked && attr.ngClick ? attr.checked : !ngModelCtrl.$viewValue;
188188

189189
ngModelCtrl.$setViewValue(viewValue, ev && ev.type);
190190
ngModelCtrl.$render();

src/components/checkbox/checkbox.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ describe('mdCheckbox', function() {
272272
expect(checkbox.hasClass(CHECKED_CSS)).toBe(false);
273273
});
274274

275+
it('properly handles click event when ng-checked is set', function() {
276+
pageScope.checked = false;
277+
var checkbox = compileAndLink('<md-checkbox ng-checked="checked"></md-checkbox>');
278+
279+
checkbox.triggerHandler('click');
280+
expect(isChecked(checkbox)).toBe(true);
281+
});
282+
275283
it('should mark the checkbox as selected on load with ng-checked', function() {
276284
pageScope.isChecked = function() { return true; };
277285

0 commit comments

Comments
 (0)