Skip to content

Commit 353d9ef

Browse files
committed
fix(animations): prevent animations when in a noopanimations module
1 parent 6a82c65 commit 353d9ef

File tree

8 files changed

+102
-65
lines changed

8 files changed

+102
-65
lines changed

package-lock.json

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
"node": ">= 5.4.1"
2727
},
2828
"dependencies": {
29-
"@angular/animations": "6.0.0-rc.4",
30-
"@angular/common": "6.0.0-rc.4",
31-
"@angular/compiler": "6.0.0-rc.4",
32-
"@angular/core": "6.0.0-rc.4",
33-
"@angular/forms": "6.0.0-rc.4",
34-
"@angular/platform-browser": "6.0.0-rc.4",
29+
"@angular/animations": "6.0.0-rc.5",
30+
"@angular/common": "6.0.0-rc.5",
31+
"@angular/compiler": "6.0.0-rc.5",
32+
"@angular/core": "6.0.0-rc.5",
33+
"@angular/forms": "6.0.0-rc.5",
34+
"@angular/platform-browser": "6.0.0-rc.5",
3535
"core-js": "^2.4.1",
3636
"rxjs": "6.0.0-ucandoit-rc.6",
3737
"systemjs": "0.19.43",
@@ -42,13 +42,13 @@
4242
"devDependencies": {
4343
"@angular-devkit/core": "^0.5.6",
4444
"@angular-devkit/schematics": "^0.5.6",
45-
"@angular/bazel": "6.0.0-rc.4",
46-
"@angular/compiler-cli": "6.0.0-rc.4",
47-
"@angular/http": "6.0.0-rc.4",
48-
"@angular/platform-browser-dynamic": "6.0.0-rc.4",
49-
"@angular/platform-server": "6.0.0-rc.4",
50-
"@angular/router": "6.0.0-rc.4",
51-
"@angular/upgrade": "6.0.0-rc.4",
45+
"@angular/bazel": "6.0.0-rc.5",
46+
"@angular/compiler-cli": "6.0.0-rc.5",
47+
"@angular/http": "6.0.0-rc.5",
48+
"@angular/platform-browser-dynamic": "6.0.0-rc.5",
49+
"@angular/platform-server": "6.0.0-rc.5",
50+
"@angular/router": "6.0.0-rc.5",
51+
"@angular/upgrade": "6.0.0-rc.5",
5252
"@bazel/ibazel": "0.3.1",
5353
"@google-cloud/storage": "^1.1.1",
5454
"@schematics/angular": "^0.5.6",

src/demo-app/demo-app-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ApplicationRef, NgModule} from '@angular/core';
1010
import {BrowserModule} from '@angular/platform-browser';
1111
import {HttpClientModule} from '@angular/common/http';
1212
import {RouterModule} from '@angular/router';
13-
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
13+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1414
import {ALL_ROUTES} from './demo-app/routes';
1515
import {EntryApp} from './demo-app/demo-app';
1616
import {DemoModule} from './demo-app/demo-module';
@@ -20,7 +20,7 @@ import {AccessibilityDemoModule} from './a11y/a11y-module';
2020
@NgModule({
2121
imports: [
2222
BrowserModule,
23-
BrowserAnimationsModule,
23+
NoopAnimationsModule,
2424
HttpClientModule,
2525
DemoModule,
2626
AccessibilityDemoModule,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// If the mat-animation-noop class is present on the components root element,
2+
// prevent non css animations from running.
3+
@mixin noop-animation() {
4+
@at-root .mat-animation-noop#{&} {
5+
transition-property: none;
6+
transition: none;
7+
animation: none;
8+
}
9+
}

src/lib/progress-bar/progress-bar.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3+
@import '../core/style/noop-animation';
34

45
$mat-progress-bar-height: 5px !default;
56
$mat-progress-bar-full-animation-duration: 2000ms !default;
67
$mat-progress-bar-piece-animation-duration: 250ms !default;
78

89

910
.mat-progress-bar {
11+
@include noop-animation();
1012
display: block;
1113
// Height is provided for mat-progress-bar to act as a default.
1214
height: $mat-progress-bar-height;
@@ -33,6 +35,7 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
3335
// The progress bar buffer is the bar indicator showing the buffer value and is only visible
3436
// beyond the current value of the primary progress bar.
3537
.mat-progress-bar-buffer {
38+
@include noop-animation();
3639
transform-origin: top left;
3740
transition: transform $mat-progress-bar-piece-animation-duration ease;
3841
}
@@ -45,13 +48,15 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
4548

4649
// The progress bar fill fills the progress bar with the indicator color.
4750
.mat-progress-bar-fill {
51+
@include noop-animation();
4852
animation: none;
4953
transform-origin: top left;
5054
transition: transform $mat-progress-bar-piece-animation-duration ease;
5155
}
5256

5357
// A pseudo element is created for each progress bar bar that fills with the indicator color.
5458
.mat-progress-bar-fill::after {
59+
@include noop-animation();
5560
animation: none;
5661
content: '';
5762
display: inline-block;
@@ -76,23 +81,27 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
7681
&[mode='indeterminate'],
7782
&[mode='query'] {
7883
.mat-progress-bar-fill {
84+
@include noop-animation();
7985
transition: none;
8086
}
8187
.mat-progress-bar-primary {
8288
// Avoids stacked animation tearing in Firefox >= 57.
89+
@include noop-animation();
8390
@include backface-visibility(hidden);
8491
animation: mat-progress-bar-primary-indeterminate-translate
8592
$mat-progress-bar-full-animation-duration infinite linear;
8693
left: -145.166611%;
8794
}
8895
.mat-progress-bar-primary.mat-progress-bar-fill::after {
8996
// Avoids stacked animation tearing in Firefox >= 57.
97+
@include noop-animation();
9098
@include backface-visibility(hidden);
9199
animation: mat-progress-bar-primary-indeterminate-scale
92100
$mat-progress-bar-full-animation-duration infinite linear;
93101
}
94102
.mat-progress-bar-secondary {
95103
// Avoids stacked animation tearing in Firefox >= 57.
104+
@include noop-animation();
96105
@include backface-visibility(hidden);
97106
animation: mat-progress-bar-secondary-indeterminate-translate
98107
$mat-progress-bar-full-animation-duration infinite linear;
@@ -101,6 +110,7 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
101110
}
102111
.mat-progress-bar-secondary.mat-progress-bar-fill::after {
103112
// Avoids stacked animation tearing in Firefox >= 57.
113+
@include noop-animation();
104114
@include backface-visibility(hidden);
105115
animation: mat-progress-bar-secondary-indeterminate-scale
106116
$mat-progress-bar-full-animation-duration infinite linear;
@@ -110,6 +120,7 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
110120
&[mode='buffer'] {
111121
.mat-progress-bar-background {
112122
// Avoids stacked animation tearing in Firefox >= 57.
123+
@include noop-animation();
113124
@include backface-visibility(hidden);
114125
animation: mat-progress-bar-background-scroll
115126
$mat-progress-bar-piece-animation-duration infinite linear;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import {
99
Component,
1010
ChangeDetectionStrategy,
1111
ElementRef,
12+
Inject,
1213
Input,
14+
Optional,
1315
ViewEncapsulation
1416
} from '@angular/core';
17+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1518
import {CanColor, mixinColor} from '@angular/material/core';
1619

1720
// TODO(josephperrott): Benchpress tests.
@@ -42,6 +45,7 @@ let progressbarId = 0;
4245
'[attr.aria-valuenow]': 'value',
4346
'[attr.mode]': 'mode',
4447
'class': 'mat-progress-bar',
48+
'[class.mat-animation-noop]': `_animationMode === 'NoopAnimations'`,
4549
},
4650
inputs: ['color'],
4751
templateUrl: 'progress-bar.html',
@@ -51,7 +55,9 @@ let progressbarId = 0;
5155
})
5256
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {
5357

54-
constructor(public _elementRef: ElementRef) {
58+
59+
constructor(public _elementRef: ElementRef,
60+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode: string) {
5561
super(_elementRef);
5662
}
5763

0 commit comments

Comments
 (0)