Skip to content

Commit 35ad57a

Browse files
committed
/.
1 parent dfc580d commit 35ad57a

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/demo-app/checkbox/checkbox-demo.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,20 @@ <h1>md-checkbox: Basic Example</h1>
4545

4646
<h1>Nested Checklist</h1>
4747
<md-checkbox-demo-nested-checklist></md-checkbox-demo-nested-checklist>
48+
49+
<md-card>
50+
<md-checkbox [(ngModel)]="checked" [indeterminate]="indeterminate">
51+
Active
52+
</md-checkbox>
53+
<br>
54+
<label>
55+
<input type="checkbox" [(ngModel)]="checked" [(indeterminate)]="indeterminate">
56+
Active
57+
</label>
58+
<br><br><br>
59+
<button (click)="checked=!checked">Toggle Checked: {{checked}}</button>
60+
&nbsp;
61+
<button (click)="indeterminate=!indeterminate">Toggle Indeterminate: {{indeterminate}}</button><br>
62+
63+
64+
</md-card>

src/demo-app/checkbox/checkbox-demo.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class MdCheckboxDemoNestedChecklist {
6363
styleUrls: ['checkbox-demo.css'],
6464
})
6565
export class CheckboxDemo {
66+
checked: boolean = true;
67+
indeterminate: boolean = true;
68+
6669
isIndeterminate: boolean = false;
6770
isChecked: boolean = false;
6871
isDisabled: boolean = false;

src/lib/checkbox/checkbox.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class MdCheckbox implements ControlValueAccessor {
160160
}
161161

162162
/**
163-
* Whether the checkbox is checked. Note that setting `checked` will immediately set
163+
* Whether the checkbox is checked. Note that setting `checked` to true will immediately set
164164
* `indeterminate` to false.
165165
*/
166166
@Input() get checked() {
@@ -169,7 +169,9 @@ export class MdCheckbox implements ControlValueAccessor {
169169

170170
set checked(checked: boolean) {
171171
if (checked != this.checked) {
172-
this._indeterminate = false;
172+
if (checked) {
173+
this.indeterminate = false;
174+
}
173175
this._checked = checked;
174176
this._transitionCheckState(
175177
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
@@ -179,7 +181,7 @@ export class MdCheckbox implements ControlValueAccessor {
179181
/**
180182
* Whether the checkbox is indeterminate. This is also known as "mixed" mode and can be used to
181183
* represent a checkbox with three states, e.g. a checkbox that represents a nested list of
182-
* checkable items. Note that whenever `checked` is set, indeterminate is immediately set to
184+
* checkable items. Note that whenever `checked` is set to true, indeterminate is immediately set to
183185
* false. This differs from the web platform in that indeterminate state on native
184186
* checkboxes is only remove when the user manually checks the checkbox (rather than setting the
185187
* `checked` property programmatically). However, we feel that this behavior is more accommodating

0 commit comments

Comments
 (0)