Skip to content

Commit 2f9aa63

Browse files
committed
fix(checkbox): fix checkbox animation when moved between view containers
1 parent 88df7ee commit 2f9aa63

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/lib/checkbox/checkbox.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ describe('MatCheckbox', () => {
220220

221221
expect(checkboxInstance.checked).toBe(false);
222222
expect(checkboxInstance.indeterminate).toBe(false);
223+
224+
flush();
223225
}));
224226

225227
it('should add and remove disabled state', () => {
@@ -539,6 +541,19 @@ describe('MatCheckbox', () => {
539541
it('should not initially have any transition classes', () => {
540542
expect(checkboxNativeElement).not.toMatch(/^mat\-checkbox\-anim/g);
541543
});
544+
545+
it('should not have transition classes when animation ends', fakeAsync(() => {
546+
testComponent.isIndeterminate = true;
547+
fixture.detectChanges();
548+
549+
expect(checkboxNativeElement.classList)
550+
.toContain('mat-checkbox-anim-unchecked-indeterminate');
551+
552+
flush();
553+
554+
expect(checkboxNativeElement.classList)
555+
.not.toContain('mat-checkbox-anim-unchecked-indeterminate');
556+
}));
542557
});
543558

544559
describe(`when MAT_CHECKBOX_CLICK_ACTION is 'check'`, () => {

src/lib/checkbox/checkbox.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
291291

292292
if (this._currentAnimationClass.length > 0) {
293293
element.classList.add(this._currentAnimationClass);
294+
295+
// Remove the animation class to avoid animation when the checkbox is moved between containers
296+
const animationClass = this._currentAnimationClass;
297+
setTimeout(() => {
298+
element.classList.remove(animationClass);
299+
}, 1000);
294300
}
295301
}
296302

0 commit comments

Comments
 (0)