Skip to content

Commit eb28374

Browse files
committed
feat: respect animation @.disabled binding
For custom CSS transitions we currently only check whether the `NoopAnimationsModule` is used or not. If noop animations are used, we apply a CSS class that can be used to set the `transition` or `animation` to `none`. Since developers can toggle the animations dynamically through the `[@.disabled]` binding (which goes down the component tree), we should also respect this binding because such binding is commonly used. Also instead of using a mixin that does magic, we should explicitly manage the selectors in order to keep the generated CSS as predictable and small as possible.
1 parent 26c73e0 commit eb28374

File tree

15 files changed

+49
-57
lines changed

15 files changed

+49
-57
lines changed

src/lib/button/_button-base.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
33
@import '../core/style/button-common';
4-
@import '../core/style/noop-animation';
54

65

76
// Flat and raised button standards
@@ -76,14 +75,17 @@ $mat-mini-fab-padding: 8px !default;
7675
// Applies styles to buttons with backgrounds: raised, fab, and mini-fab
7776
@mixin mat-raised-button {
7877
@include mat-button-base;
79-
@include _noop-animation();
8078

8179
// Force hardware acceleration.
8280
transform: translate3d(0, 0, 0);
8381

8482
// Animation.
8583
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,
8684
mat-elevation-transition-property-value();
85+
86+
&._mat-animation-noopable, .ng-animate-disabled & {
87+
transition: none;
88+
}
8789
}
8890

8991
// Applies styles to fab and mini-fab button types only

src/lib/button/button.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113
transition: $mat-button-focus-transition;
114114

115-
._mat-animation-noopable & {
115+
._mat-animation-noopable &, .ng-animate-disabled & {
116116
transition: none;
117117
}
118118

src/lib/checkbox/checkbox.scss

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

98
// Manual calculation done on SVG
@@ -174,12 +173,14 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
174173
}
175174

176175
.mat-checkbox {
177-
@include _noop-animation();
178-
179176
// Animation
180177
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,
181178
mat-elevation-transition-property-value();
182179

180+
&._mat-animation-noopable, .ng-animate-disabled & {
181+
transition: none;
182+
}
183+
183184
cursor: pointer;
184185
-webkit-tap-highlight-color: transparent;
185186

@@ -237,7 +238,7 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
237238
style: solid;
238239
}
239240

240-
._mat-animation-noopable & {
241+
._mat-animation-noopable &, .ng-animate-disabled & {
241242
transition: none;
242243
}
243244

@@ -260,7 +261,7 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
260261
$mat-linear-out-slow-in-timing-function,
261262
opacity $mat-checkbox-transition-duration $mat-linear-out-slow-in-timing-function;
262263

263-
._mat-animation-noopable & {
264+
._mat-animation-noopable &, .ng-animate-disabled & {
264265
transition: none;
265266
}
266267
}

src/lib/core/selection/pseudo-checkbox/pseudo-checkbox.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@import '../../style/checkbox-common';
2-
@import '../../style/noop-animation';
32

43
// Padding inside of a pseudo checkbox.
54
$_mat-pseudo-checkbox-padding: $mat-checkbox-border-width * 2;
@@ -36,7 +35,9 @@ $_mat-pseudo-checkmark-size: $mat-checkbox-size - (2 * $_mat-pseudo-checkbox-pad
3635
border-color: transparent;
3736
}
3837

39-
@include _noop-animation {
38+
&._mat-animation-noopable, .ng-animate-disabled & {
39+
transition: none;
40+
4041
&::after {
4142
transition: none;
4243
}

src/lib/core/style/_noop-animation.scss

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/lib/form-field/form-field-fill.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ $mat-form-field-fill-subscript-padding:
6262
}
6363
}
6464

65-
&._mat-animation-noopable:not(.mat-form-field-disabled) .mat-form-field-flex:hover {
66-
& ~ .mat-form-field-underline .mat-form-field-ripple {
67-
transition: none;
65+
&:not(.mat-form-field-disabled) {
66+
&._mat-animation-noopable, .ng-animate-disabled & {
67+
.mat-form-field-flex:hover ~ .mat-form-field-underline .mat-form-field-ripple {
68+
transition: none;
69+
}
6870
}
6971
}
7072

src/lib/form-field/form-field-outline.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $mat-form-field-outline-subscript-padding:
133133
padding: 0 $mat-form-field-outline-subscript-padding;
134134
}
135135

136-
&._mat-animation-noopable {
136+
&._mat-animation-noopable, .ng-animate-disabled & {
137137
&:not(.mat-form-field-disabled) .mat-form-field-flex:hover ~ .mat-form-field-outline,
138138
.mat-form-field-outline,
139139
.mat-form-field-outline-start,

src/lib/form-field/form-field-standard.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ $mat-form-field-standard-padding-top: 0.75em !default;
5959
}
6060
}
6161

62-
&._mat-animation-noopable:not(.mat-form-field-disabled) .mat-form-field-flex:hover {
63-
& ~ .mat-form-field-underline .mat-form-field-ripple {
64-
transition: none;
62+
&:not(.mat-form-field-disabled) {
63+
&._mat-animation-noopable, .ng-animate-disabled & {
64+
.mat-form-field-flex:hover ~ .mat-form-field-underline .mat-form-field-ripple {
65+
transition: none;
66+
}
6567
}
6668
}
6769
}

src/lib/form-field/form-field.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ $mat-form-field-default-infix-width: 180px !default;
222222
position: relative;
223223
}
224224

225-
.mat-form-field._mat-animation-noopable {
225+
.mat-form-field._mat-animation-noopable, .ng-animate-disabled .mat-form-field {
226226
.mat-form-field-label,
227227
.mat-form-field-ripple {
228228
transition: none;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import '../core/style/variables';
22
@import '../core/style/vendor-prefixes';
3-
@import '../core/style/noop-animation';
43
@import '../../cdk/a11y/a11y';
54

65
$mat-progress-bar-height: 4px !default;
@@ -9,7 +8,6 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
98

109

1110
.mat-progress-bar {
12-
@include _noop-animation();
1311
display: block;
1412
// Height is provided for mat-progress-bar to act as a default.
1513
height: $mat-progress-bar-height;
@@ -18,6 +16,10 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
1816
transition: opacity $mat-progress-bar-piece-animation-duration linear;
1917
width: 100%;
2018

19+
&._mat-animation-noopable, .ng-animate-disabled & {
20+
transition: none;
21+
}
22+
2123
// Base styles that are re-used across all of the progress bar children.
2224
.mat-progress-bar-element, .mat-progress-bar-fill::after {
2325
height: 100%;
@@ -137,7 +139,7 @@ $mat-progress-bar-piece-animation-duration: 250ms !default;
137139
}
138140

139141
// Disabled animations handling.
140-
&._mat-animation-noopable {
142+
&._mat-animation-noopable, .ng-animate-disabled & {
141143
.mat-progress-bar-fill,
142144
.mat-progress-bar-fill::after,
143145
.mat-progress-bar-buffer,

src/lib/progress-spinner/progress-spinner.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
@import '../core/style/variables';
2-
@import '../core/style/noop-animation';
3-
42

53
// Animation config
64
$mat-progress-spinner-stroke-rotate-fallback-duration: 10 * 1000ms !default;
@@ -13,6 +11,15 @@ $_mat-progress-spinner-default-circumference: $pi * $_mat-progress-spinner-defau
1311
display: block;
1412
position: relative;
1513

14+
&._mat-animation-noopable, .ng-animate-disabled & {
15+
animation: none;
16+
17+
circle {
18+
animation: none;
19+
transition: none;
20+
}
21+
}
22+
1623
svg {
1724
position: absolute;
1825
transform: rotate(-90deg);
@@ -23,19 +30,16 @@ $_mat-progress-spinner-default-circumference: $pi * $_mat-progress-spinner-defau
2330
}
2431

2532
circle {
26-
@include _noop-animation();
2733
fill: transparent;
2834
transform-origin: center;
2935
transition: stroke-dashoffset 225ms linear;
3036
}
3137

3238
&.mat-progress-spinner-indeterminate-animation[mode='indeterminate'] {
33-
@include _noop-animation();
3439
animation: mat-progress-spinner-linear-rotate $swift-ease-in-out-duration * 4
3540
linear infinite;
3641

3742
circle {
38-
@include _noop-animation();
3943
transition-property: stroke;
4044
// Note: we multiply the duration by 8, because the animation is spread out in 8 stages.
4145
animation-duration: $swift-ease-in-out-duration * 8;
@@ -45,14 +49,12 @@ $_mat-progress-spinner-default-circumference: $pi * $_mat-progress-spinner-defau
4549
}
4650

4751
&.mat-progress-spinner-indeterminate-fallback-animation[mode='indeterminate'] {
48-
@include _noop-animation();
4952
animation: mat-progress-spinner-stroke-rotate-fallback
5053
$mat-progress-spinner-stroke-rotate-fallback-duration
5154
$mat-progress-spinner-stroke-rotate-fallback-ease
5255
infinite;
5356

5457
circle {
55-
@include _noop-animation();
5658
transition-property: stroke;
5759
}
5860
}

src/lib/radio/radio.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $mat-radio-ripple-radius: 20px;
4949
radius: 50%;
5050
}
5151

52-
._mat-animation-noopable & {
52+
._mat-animation-noopable &, .ng-animate-disabled & {
5353
transition: none;
5454
}
5555
}
@@ -69,7 +69,7 @@ $mat-radio-ripple-radius: 20px;
6969
// IE to flash the entire circle for a couple of frames, throwing off the entire animation.
7070
transform: scale(0.001);
7171

72-
._mat-animation-noopable & {
72+
._mat-animation-noopable &, .ng-animate-disabled & {
7373
transition: none;
7474
}
7575

src/lib/select/select.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
6868
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
6969
}
7070

71-
._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty & {
71+
._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty &,
72+
.ng-animate-disabled .mat-form-field-appearance-standard .mat-select.mat-select-empty & {
7273
transition: none;
7374
}
7475
}
@@ -121,7 +122,7 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
121122
transition: color $swift-ease-out-duration $swift-ease-out-duration / 3
122123
$swift-ease-out-timing-function;
123124

124-
._mat-animation-noopable & {
125+
._mat-animation-noopable &, .ng-animate-disabled & {
125126
transition: none;
126127
}
127128

src/lib/slide-toggle/slide-toggle.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
115115
transition-duration: 0ms;
116116
}
117117

118-
._mat-animation-noopable & {
118+
._mat-animation-noopable &, .ng-animate-disabled & {
119119
transition: none;
120120
}
121121

@@ -170,7 +170,7 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
170170
transition-property: background-color;
171171
transition-delay: 50ms;
172172

173-
._mat-animation-noopable & {
173+
._mat-animation-noopable &, .ng-animate-disabled & {
174174
transition: none;
175175
}
176176
}

src/lib/slider/slider.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ $mat-slider-focus-ring-size: 30px !default;
470470
}
471471

472472
// Slider inside a component with disabled animations.
473-
.mat-slider._mat-animation-noopable {
473+
.mat-slider._mat-animation-noopable,
474+
.ng-animate-disabled .mat-slider {
474475
.mat-slider-track-fill,
475476
.mat-slider-track-background,
476477
.mat-slider-ticks,

0 commit comments

Comments
 (0)