Skip to content

Commit 6515d9c

Browse files
crisbetotinayuangao
authored andcommitted
fix(checkbox): disable animations when using NoopAnimationsModule (#11249)
* Disables all checkbox animations when using the `NoopAnimationsModule`. Doesn't include ripples which were done in #11205. * Removes a method that was only used once and inlines the logic.
1 parent 4feaabc commit 6515d9c

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/lib/checkbox/checkbox.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@import '../core/style/checkbox-common';
44
@import '../core/ripple/ripple';
55
@import '../core/style/layout-common';
6+
@import '../core/style/noop-animation';
67

78
// Manual calculation done on SVG
89
$_mat-checkbox-mark-path-length: 22.910259;
@@ -179,6 +180,8 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
179180
}
180181

181182
.mat-checkbox {
183+
@include _noop-animation();
184+
182185
// Animation
183186
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,
184187
mat-elevation-transition-property-value();
@@ -234,6 +237,10 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
234237
width: $mat-checkbox-border-width;
235238
style: solid;
236239
}
240+
241+
._mat-animation-noopable & {
242+
transition: none;
243+
}
237244
}
238245

239246
.mat-checkbox-background {
@@ -245,6 +252,10 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
245252
transition: background-color $mat-checkbox-transition-duration
246253
$mat-linear-out-slow-in-timing-function,
247254
opacity $mat-checkbox-transition-duration $mat-linear-out-slow-in-timing-function;
255+
256+
._mat-animation-noopable & {
257+
transition: none;
258+
}
248259
}
249260

250261
.mat-checkbox-checkmark {

src/lib/checkbox/checkbox.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
RippleRef,
4040
} from '@angular/material/core';
4141
import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from './checkbox-config';
42+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4243

4344

4445
// Increasing integer for generating unique ids for checkbox components.
@@ -108,6 +109,7 @@ export const _MatCheckboxMixinBase =
108109
'[class.mat-checkbox-checked]': 'checked',
109110
'[class.mat-checkbox-disabled]': 'disabled',
110111
'[class.mat-checkbox-label-before]': 'labelPosition == "before"',
112+
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
111113
},
112114
providers: [MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR],
113115
inputs: ['disableRipple', 'color', 'tabIndex'],
@@ -184,7 +186,8 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
184186
private _focusMonitor: FocusMonitor,
185187
@Attribute('tabindex') tabIndex: string,
186188
@Optional() @Inject(MAT_CHECKBOX_CLICK_ACTION)
187-
private _clickAction: MatCheckboxClickAction) {
189+
private _clickAction: MatCheckboxClickAction,
190+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
188191
super(elementRef);
189192

190193
this.tabIndex = parseInt(tabIndex) || 0;
@@ -322,7 +325,11 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
322325
if (!this._focusRipple && focusOrigin === 'keyboard') {
323326
this._focusRipple = this.ripple.launch(0, 0, {persistent: true});
324327
} else if (!focusOrigin) {
325-
this._removeFocusRipple();
328+
if (this._focusRipple) {
329+
this._focusRipple.fadeOut();
330+
this._focusRipple = null;
331+
}
332+
326333
this._onTouched();
327334
}
328335
}
@@ -390,6 +397,11 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
390397

391398
private _getAnimationClassForCheckStateTransition(
392399
oldState: TransitionCheckState, newState: TransitionCheckState): string {
400+
// Don't transition if animations are disabled.
401+
if (this._animationMode === 'NoopAnimations') {
402+
return '';
403+
}
404+
393405
let animSuffix: string = '';
394406

395407
switch (oldState) {
@@ -420,12 +432,4 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
420432

421433
return `mat-checkbox-anim-${animSuffix}`;
422434
}
423-
424-
/** Fades out the focus state ripple. */
425-
private _removeFocusRipple(): void {
426-
if (this._focusRipple) {
427-
this._focusRipple.fadeOut();
428-
this._focusRipple = null;
429-
}
430-
}
431435
}

0 commit comments

Comments
 (0)