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 @@ -221,6 +221,8 @@ describe('MatCheckbox', () => {
221221
222222 expect ( checkboxInstance . checked ) . toBe ( false ) ;
223223 expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
224+
225+ flush ( ) ;
224226 } ) ) ;
225227
226228 it ( 'should add and remove disabled state' , ( ) => {
@@ -540,6 +542,19 @@ describe('MatCheckbox', () => {
540542 it ( 'should not initially have any transition classes' , ( ) => {
541543 expect ( checkboxNativeElement ) . not . toMatch ( / ^ m a t \- c h e c k b o x \- a n i m / g) ;
542544 } ) ;
545+
546+ it ( 'should not have transition classes when animation ends' , fakeAsync ( ( ) => {
547+ testComponent . isIndeterminate = true ;
548+ fixture . detectChanges ( ) ;
549+
550+ expect ( checkboxNativeElement . classList )
551+ . toContain ( 'mat-checkbox-anim-unchecked-indeterminate' ) ;
552+
553+ flush ( ) ;
554+
555+ expect ( checkboxNativeElement . classList )
556+ . not . toContain ( 'mat-checkbox-anim-unchecked-indeterminate' ) ;
557+ } ) ) ;
543558 } ) ;
544559
545560 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