Skip to content

Commit f4323b2

Browse files
tinayuangaokara
authored andcommitted
fix(checkbox): show checkbox animation only if user click or indeterminate state (#3137)
Fixes #2783
1 parent 5cc50d2 commit f4323b2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/lib/checkbox/checkbox.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ describe('MdCheckbox', () => {
384384

385385
describe('state transition css classes', () => {
386386
it('should transition unchecked -> checked -> unchecked', () => {
387-
testComponent.isChecked = true;
387+
inputElement.click();
388388
fixture.detectChanges();
389389
expect(checkboxNativeElement.classList).toContain('mat-checkbox-anim-unchecked-checked');
390390

391-
testComponent.isChecked = false;
391+
inputElement.click();
392392
fixture.detectChanges();
393393
expect(checkboxNativeElement.classList)
394394
.not.toContain('mat-checkbox-anim-unchecked-checked');

src/lib/checkbox/checkbox.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ export class MdCheckbox implements ControlValueAccessor {
195195
this.indeterminateChange.emit(this._indeterminate);
196196
}
197197
this._checked = checked;
198-
this._transitionCheckState(
199-
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
200198
this._changeDetectorRef.markForCheck();
201199
}
202200
}
@@ -217,13 +215,14 @@ export class MdCheckbox implements ControlValueAccessor {
217215
set indeterminate(indeterminate: boolean) {
218216
let changed = indeterminate != this._indeterminate;
219217
this._indeterminate = indeterminate;
220-
if (this._indeterminate) {
221-
this._transitionCheckState(TransitionCheckState.Indeterminate);
222-
} else {
223-
this._transitionCheckState(
224-
this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
225-
}
218+
226219
if (changed) {
220+
if (this._indeterminate) {
221+
this._transitionCheckState(TransitionCheckState.Indeterminate);
222+
} else {
223+
this._transitionCheckState(
224+
this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
225+
}
227226
this.indeterminateChange.emit(this._indeterminate);
228227
}
229228
}
@@ -348,6 +347,8 @@ export class MdCheckbox implements ControlValueAccessor {
348347

349348
if (!this.disabled) {
350349
this.toggle();
350+
this._transitionCheckState(
351+
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
351352

352353
// Emit our custom change event if the native input emitted one.
353354
// It is important to only emit it, if the native input triggered one, because
@@ -379,6 +380,8 @@ export class MdCheckbox implements ControlValueAccessor {
379380
// [checked] bound to it.
380381
if (newState === TransitionCheckState.Checked) {
381382
animSuffix = 'unchecked-checked';
383+
} else if (newState == TransitionCheckState.Indeterminate) {
384+
animSuffix = 'unchecked-indeterminate';
382385
} else {
383386
return '';
384387
}

0 commit comments

Comments
 (0)