Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/check-mdc-tests-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const config = {
'should not remove margin if initial label is set through binding',
'should re-add margin if label is added asynchronously',
'should properly update margin if label content is projected',
'should transition correctly from initially checked to indeterminate',

// TODO: the focus origin behavior needs to be implemented in the MDC checkbox
'should not change focus origin if origin not specified',
Expand Down
15 changes: 15 additions & 0 deletions src/material/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,21 @@ describe('MatCheckbox', () => {
'mat-checkbox-anim-unchecked-indeterminate',
);
}));

it('should transition correctly from initially checked to indeterminate', () => {
testComponent.isIndeterminate = false;
testComponent.isChecked = true;
fixture.detectChanges();

expect(checkboxNativeElement.className).not.toMatch(/^mat\-checkbox\-anim/g);

testComponent.isIndeterminate = testComponent.isChecked = true;
fixture.detectChanges();

expect(checkboxNativeElement.classList).toContain(
'mat-checkbox-anim-checked-indeterminate',
);
});
});

describe(`when MAT_CHECKBOX_CLICK_ACTION is 'check'`, () => {
Expand Down
6 changes: 4 additions & 2 deletions src/material/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export abstract class _MatCheckboxBase<E>
if (oldState === newState || !element) {
return;
}
if (this._currentAnimationClass.length > 0) {
if (this._currentAnimationClass) {
element.classList.remove(this._currentAnimationClass);
}

Expand Down Expand Up @@ -438,7 +438,9 @@ export abstract class _MatCheckboxBase<E>
if (newState === TransitionCheckState.Checked) {
return this._animationClasses.uncheckedToChecked;
} else if (newState == TransitionCheckState.Indeterminate) {
return this._animationClasses.uncheckedToIndeterminate;
return this._checked
? this._animationClasses.checkedToIndeterminate
: this._animationClasses.uncheckedToIndeterminate;
}
break;
case TransitionCheckState.Unchecked:
Expand Down