Skip to content

Commit 6d1098c

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

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
8181
host: {
8282
'role': 'progressbar',
8383
'class': 'mat-progress-spinner',
84-
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
84+
'[class._mat-animation-noopable]': `_noopAnimations`,
8585
'[style.width.px]': 'diameter',
8686
'[style.height.px]': 'diameter',
8787
'[attr.aria-valuemin]': 'mode === "determinate" ? 0 : null',
@@ -110,6 +110,9 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
110110
*/
111111
private static styleTag: HTMLStyleElement|null = null;
112112

113+
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
114+
_noopAnimations: boolean = this.animationMode === 'NoopAnimations' && this.platform.isBrowser;
115+
113116
/** The diameter of the progress spinner (will set width and height of svg). */
114117
@Input()
115118
get diameter(): number { return this._diameter; }
@@ -145,9 +148,9 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
145148
}
146149

147150
constructor(public _elementRef: ElementRef,
148-
platform: Platform,
151+
public platform: Platform,
149152
@Optional() @Inject(DOCUMENT) private _document: any,
150-
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
153+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private animationMode?: string) {
151154

152155
super(_elementRef);
153156
this._fallbackAnimation = platform.EDGE || platform.TRIDENT;
@@ -236,7 +239,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
236239
'role': 'progressbar',
237240
'mode': 'indeterminate',
238241
'class': 'mat-spinner mat-progress-spinner',
239-
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
242+
'[class._mat-animation-noopable]': `_noopAnimations`,
240243
'[style.width.px]': 'diameter',
241244
'[style.height.px]': 'diameter',
242245
},
@@ -249,8 +252,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
249252
export class MatSpinner extends MatProgressSpinner {
250253
constructor(elementRef: ElementRef, platform: Platform,
251254
@Optional() @Inject(DOCUMENT) document: any,
252-
@Optional() @Inject(ANIMATION_MODULE_TYPE) _animationMode?: string) {
253-
super(elementRef, platform, document, _animationMode);
255+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
256+
super(elementRef, platform, document, animationMode);
254257
this.mode = 'indeterminate';
255258
}
256259
}

0 commit comments

Comments
 (0)