File tree 2 files changed +26
-0
lines changed 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,8 @@ describe('MatCheckbox', () => {
207
207
208
208
expect ( checkboxInstance . checked ) . toBe ( false ) ;
209
209
expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
210
+
211
+ flush ( ) ;
210
212
} ) ) ;
211
213
212
214
it ( 'should add and remove disabled state' , ( ) => {
@@ -526,6 +528,19 @@ describe('MatCheckbox', () => {
526
528
it ( 'should not initially have any transition classes' , ( ) => {
527
529
expect ( checkboxNativeElement ) . not . toMatch ( / ^ m a t \- c h e c k b o x \- a n i m / g) ;
528
530
} ) ;
531
+
532
+ it ( 'should not have transition classes when animation ends' , fakeAsync ( ( ) => {
533
+ testComponent . isIndeterminate = true ;
534
+ fixture . detectChanges ( ) ;
535
+
536
+ expect ( checkboxNativeElement . classList )
537
+ . toContain ( 'mat-checkbox-anim-unchecked-indeterminate' ) ;
538
+
539
+ flush ( ) ;
540
+
541
+ expect ( checkboxNativeElement . classList )
542
+ . not . toContain ( 'mat-checkbox-anim-unchecked-indeterminate' ) ;
543
+ } ) ) ;
529
544
} ) ;
530
545
531
546
describe ( `when MAT_CHECKBOX_CLICK_ACTION is 'check'` , ( ) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
19
19
forwardRef ,
20
20
Inject ,
21
21
Input ,
22
+ NgZone ,
22
23
OnDestroy ,
23
24
Optional ,
24
25
Output ,
@@ -184,6 +185,7 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
184
185
constructor ( elementRef : ElementRef ,
185
186
private _changeDetectorRef : ChangeDetectorRef ,
186
187
private _focusMonitor : FocusMonitor ,
188
+ private _ngZone : NgZone ,
187
189
@Attribute ( 'tabindex' ) tabIndex : string ,
188
190
@Optional ( ) @Inject ( MAT_CHECKBOX_CLICK_ACTION )
189
191
private _clickAction : MatCheckboxClickAction ,
@@ -307,6 +309,15 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
307
309
308
310
if ( this . _currentAnimationClass . length > 0 ) {
309
311
element . classList . add ( this . _currentAnimationClass ) ;
312
+
313
+ // Remove the animation class to avoid animation when the checkbox is moved between containers
314
+ const animationClass = this . _currentAnimationClass ;
315
+
316
+ this . _ngZone . runOutsideAngular ( ( ) => {
317
+ setTimeout ( ( ) => {
318
+ element . classList . remove ( animationClass ) ;
319
+ } , 1000 ) ;
320
+ } ) ;
310
321
}
311
322
}
312
323
You can’t perform that action at this time.
0 commit comments