Skip to content

Commit 9567156

Browse files
committed
fix(progress-spinner, progress-bar): Do not prevent animations while SSR
1 parent 6b7196b commit 9567156

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/lib/progress-bar/progress-bar.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '@angular/core';
1717
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1818
import {CanColor, mixinColor} from '@angular/material/core';
19+
import {Platform} from '@angular/cdk/platform';
1920

2021
// TODO(josephperrott): Benchpress tests.
2122
// TODO(josephperrott): Add ARIA attributes for progress bar "for".
@@ -45,7 +46,7 @@ let progressbarId = 0;
4546
'[attr.aria-valuenow]': 'value',
4647
'[attr.mode]': 'mode',
4748
'class': 'mat-progress-bar',
48-
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
49+
'[class._mat-animation-noopable]': `_noopAnimations`,
4950
},
5051
inputs: ['color'],
5152
templateUrl: 'progress-bar.html',
@@ -55,9 +56,13 @@ let progressbarId = 0;
5556
})
5657
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {
5758

59+
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
60+
_noopAnimations: boolean =
61+
this.animationMode === 'NoopAnimations' && !!this.platform && this.platform.isBrowser;
5862

5963
constructor(public _elementRef: ElementRef,
60-
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
64+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public animationMode?: string,
65+
@Optional() private platform?: Platform) {
6166
super(_elementRef);
6267
}
6368

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export interface MatProgressSpinnerDefaultOptions {
5050
diameter?: number;
5151
/** Width of the spinner's stroke. */
5252
strokeWidth?: number;
53+
/**
54+
* Whether the animations should be force to be enabled, ignoring if the current environment is
55+
* using NoopAnimationsModule.
56+
*/
57+
_forceAnimations?: boolean;
5358
}
5459

5560
/** Injection token to be used to override the default options for `mat-progress-spinner`. */
@@ -102,7 +107,7 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
102107
host: {
103108
'role': 'progressbar',
104109
'class': 'mat-progress-spinner',
105-
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
110+
'[class._mat-animation-noopable]': `_noopAnimations`,
106111
'[style.width.px]': 'diameter',
107112
'[style.height.px]': 'diameter',
108113
'[attr.aria-valuemin]': 'mode === "determinate" ? 0 : null',
@@ -131,6 +136,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
131136
*/
132137
private static styleTag: HTMLStyleElement|null = null;
133138

139+
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
140+
_noopAnimations: boolean = this.animationMode === 'NoopAnimations' && (
141+
!!this.defaults && !this.defaults._forceAnimations);
142+
134143
/** The diameter of the progress spinner (will set width and height of svg). */
135144
@Input()
136145
get diameter(): number { return this._diameter; }
@@ -165,12 +174,12 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
165174
}
166175

167176
constructor(public _elementRef: ElementRef,
168-
platform: Platform,
177+
public platform: Platform,
169178
@Optional() @Inject(DOCUMENT) private _document: any,
170-
// @deletion-target 7.0.0 _animationMode and defaults parameters to be made required.
171-
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
179+
// @deletion-target 7.0.0 animationMode and defaults parameters to be made required.
180+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private animationMode?: string,
172181
@Inject(MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS)
173-
defaults?: MatProgressSpinnerDefaultOptions) {
182+
private defaults?: MatProgressSpinnerDefaultOptions) {
174183

175184
super(_elementRef);
176185
this._fallbackAnimation = platform.EDGE || platform.TRIDENT;
@@ -269,7 +278,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
269278
'role': 'progressbar',
270279
'mode': 'indeterminate',
271280
'class': 'mat-spinner mat-progress-spinner',
272-
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
281+
'[class._mat-animation-noopable]': `_noopAnimations`,
273282
'[style.width.px]': 'diameter',
274283
'[style.height.px]': 'diameter',
275284
},

0 commit comments

Comments
 (0)