File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,8 @@ describe('MatCheckbox', () => {
207207
208208 expect ( checkboxInstance . checked ) . toBe ( false ) ;
209209 expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
210+
211+ flush ( ) ;
210212 } ) ) ;
211213
212214 it ( 'should add and remove disabled state' , ( ) => {
@@ -526,6 +528,19 @@ describe('MatCheckbox', () => {
526528 it ( 'should not initially have any transition classes' , ( ) => {
527529 expect ( checkboxNativeElement ) . not . toMatch ( / ^ m a t \- c h e c k b o x \- a n i m / g) ;
528530 } ) ;
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+ } ) ) ;
529544 } ) ;
530545
531546 describe ( `when MAT_CHECKBOX_CLICK_ACTION is 'check'` , ( ) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 forwardRef ,
2020 Inject ,
2121 Input ,
22+ NgZone ,
2223 OnDestroy ,
2324 Optional ,
2425 Output ,
@@ -184,6 +185,7 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
184185 constructor ( elementRef : ElementRef ,
185186 private _changeDetectorRef : ChangeDetectorRef ,
186187 private _focusMonitor : FocusMonitor ,
188+ private _ngZone : NgZone ,
187189 @Attribute ( 'tabindex' ) tabIndex : string ,
188190 @Optional ( ) @Inject ( MAT_CHECKBOX_CLICK_ACTION )
189191 private _clickAction : MatCheckboxClickAction ,
@@ -307,6 +309,15 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
307309
308310 if ( this . _currentAnimationClass . length > 0 ) {
309311 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+ } ) ;
310321 }
311322 }
312323
You can’t perform that action at this time.
0 commit comments