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

Commit 63e1c8e

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(checkbox): initial value not being marked properly
* Fixes the checkbox not being displayed as selected, even though the model value is true. * Switches to using Angular's $set to set the attributes during compilation. Fixes #8343. Closes #8511
1 parent 9845856 commit 63e1c8e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/components/checkbox/checkbox.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ angular
3131
* @param {expression=} md-indeterminate This determines when the checkbox should be rendered as 'indeterminate'.
3232
* If a truthy expression or no value is passed in the checkbox renders in the md-indeterminate state.
3333
* If falsy expression is passed in it just looks like a normal unchecked checkbox.
34-
* The indeterminate, checked, and unchecked states are mutually exclusive. A box cannot be in any two states at the same time.
34+
* The indeterminate, checked, and unchecked states are mutually exclusive. A box cannot be in any two states at the same time.
3535
* When a checkbox is indeterminate that overrides any checked/unchecked rendering logic.
3636
*
3737
* @usage
@@ -74,11 +74,11 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
7474

7575
function compile (tElement, tAttrs) {
7676
var container = tElement.children();
77-
var mdIndeterminateStateEnabled = tAttrs.hasOwnProperty('mdIndeterminate');
77+
var mdIndeterminateStateEnabled = $mdUtil.parseAttributeBoolean(tAttrs.mdIndeterminate);
7878

79-
tAttrs.type = 'checkbox';
80-
tAttrs.tabindex = tAttrs.tabindex || '0';
81-
tElement.attr('role', tAttrs.type);
79+
tAttrs.$set('tabindex', tAttrs.tabindex || '0');
80+
tAttrs.$set('type', 'checkbox');
81+
tAttrs.$set('role', tAttrs.type);
8282

8383
// Attach a click handler in compile in order to immediately stop propagation
8484
// (especially for ng-click) when the checkbox is disabled.

src/components/checkbox/checkbox.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ describe('mdCheckbox', function() {
296296
expect(checkbox).toHaveClass(CHECKED_CSS);
297297
});
298298

299+
it('should mark the checkbox as selected, if the model is true and "md-indeterminate" is false', function() {
300+
pageScope.checked = true;
301+
var checkbox = compileAndLink('<md-checkbox ng-model="checked" md-indeterminate="false"></md-checkbox>');
302+
303+
expect(checkbox).toHaveClass(CHECKED_CSS);
304+
expect(checkbox).not.toHaveClass(INDETERMINATE_CSS);
305+
});
306+
299307
});
300308
});
301309
});

0 commit comments

Comments
 (0)