Skip to content

Commit

Permalink
fix(checkbox): show checkbox animation only if user click or indeterm…
Browse files Browse the repository at this point in the history
…inate state (#3137)

Fixes #2783
  • Loading branch information
tinayuangao authored and kara committed Mar 4, 2017
1 parent 5cc50d2 commit f4323b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ describe('MdCheckbox', () => {

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

testComponent.isChecked = false;
inputElement.click();
fixture.detectChanges();
expect(checkboxNativeElement.classList)
.not.toContain('mat-checkbox-anim-unchecked-checked');
Expand Down
19 changes: 11 additions & 8 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ export class MdCheckbox implements ControlValueAccessor {
this.indeterminateChange.emit(this._indeterminate);
}
this._checked = checked;
this._transitionCheckState(
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
this._changeDetectorRef.markForCheck();
}
}
Expand All @@ -217,13 +215,14 @@ export class MdCheckbox implements ControlValueAccessor {
set indeterminate(indeterminate: boolean) {
let changed = indeterminate != this._indeterminate;
this._indeterminate = indeterminate;
if (this._indeterminate) {
this._transitionCheckState(TransitionCheckState.Indeterminate);
} else {
this._transitionCheckState(
this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
}

if (changed) {
if (this._indeterminate) {
this._transitionCheckState(TransitionCheckState.Indeterminate);
} else {
this._transitionCheckState(
this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
}
this.indeterminateChange.emit(this._indeterminate);
}
}
Expand Down Expand Up @@ -348,6 +347,8 @@ export class MdCheckbox implements ControlValueAccessor {

if (!this.disabled) {
this.toggle();
this._transitionCheckState(
this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);

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

0 comments on commit f4323b2

Please sign in to comment.