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 @@ -221,6 +221,8 @@ describe('MatCheckbox', () => {
221
221
222
222
expect ( checkboxInstance . checked ) . toBe ( false ) ;
223
223
expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
224
+
225
+ flush ( ) ;
224
226
} ) ) ;
225
227
226
228
it ( 'should add and remove disabled state' , ( ) => {
@@ -540,6 +542,19 @@ describe('MatCheckbox', () => {
540
542
it ( 'should not initially have any transition classes' , ( ) => {
541
543
expect ( checkboxNativeElement ) . not . toMatch ( / ^ m a t \- c h e c k b o x \- a n i m / g) ;
542
544
} ) ;
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
+ } ) ) ;
543
558
} ) ;
544
559
545
560
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