Skip to content

Commit 062c5eb

Browse files
committed
fix(material/progress-spinner): slow down animations instead of fully stopping them
Reworks the progress spinner to slow down its animations, instead of fully stopping them when `prefers-reduced-motion` is enabled. Stopping the animations completely appears to be confusing for users.
1 parent 9507900 commit 062c5eb

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/material/progress-spinner/progress-spinner.scss

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
$fallbacks: m3-progress-spinner.get-tokens();
66

77
.mat-mdc-progress-spinner {
8+
--mat-progress-spinner-animation-multiplier: 1;
9+
810
// Explicitly set to `block` since the browser defaults custom elements to `inline`.
911
display: block;
1012

@@ -54,6 +56,11 @@ $fallbacks: m3-progress-spinner.get-tokens();
5456
}
5557
}
5658

59+
// Slow down the animation by 25% when the user configured their OS to reduce motion.
60+
.mat-progress-spinner-reduced-motion {
61+
--mat-progress-spinner-animation-multiplier: 1.25;
62+
}
63+
5764
.mdc-circular-progress__determinate-container,
5865
.mdc-circular-progress__indeterminate-circle-graphic,
5966
.mdc-circular-progress__indeterminate-container,
@@ -79,7 +86,8 @@ $fallbacks: m3-progress-spinner.get-tokens();
7986

8087
.mdc-circular-progress--indeterminate & {
8188
opacity: 1;
82-
animation: mdc-circular-progress-container-rotate 1568.2352941176ms linear infinite;
89+
animation: mdc-circular-progress-container-rotate
90+
calc(1568.2352941176ms * var(--mat-progress-spinner-animation-multiplier)) linear infinite;
8391
}
8492
}
8593

@@ -127,11 +135,15 @@ $fallbacks: m3-progress-spinner.get-tokens();
127135
}
128136

129137
.mdc-circular-progress--indeterminate .mdc-circular-progress__circle-left & {
130-
animation: mdc-circular-progress-left-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both;
138+
animation: mdc-circular-progress-left-spin
139+
calc(1333ms * var(--mat-progress-spinner-animation-multiplier))
140+
cubic-bezier(0.4, 0, 0.2, 1) infinite both;
131141
}
132142

133143
.mdc-circular-progress--indeterminate .mdc-circular-progress__circle-right & {
134-
animation: mdc-circular-progress-right-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both;
144+
animation: mdc-circular-progress-right-spin
145+
calc(1333ms * var(--mat-progress-spinner-animation-multiplier))
146+
cubic-bezier(0.4, 0, 0.2, 1) infinite both;
135147
}
136148
}
137149

@@ -145,7 +157,8 @@ $fallbacks: m3-progress-spinner.get-tokens();
145157

146158
.mdc-circular-progress__spinner-layer {
147159
.mdc-circular-progress--indeterminate & {
148-
animation: mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1)
160+
animation: mdc-circular-progress-spinner-layer-rotate
161+
calc(5332ms * var(--mat-progress-spinner-animation-multiplier)) cubic-bezier(0.4, 0, 0.2, 1)
149162
infinite both;
150163
}
151164
}

src/material/progress-spinner/progress-spinner.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
numberAttribute,
1818
inject,
1919
} from '@angular/core';
20-
import {_animationsDisabled, ThemePalette} from '../core';
20+
import {_getAnimationsState, ThemePalette} from '../core';
2121
import {NgTemplateOutlet} from '@angular/common';
2222

2323
/** Possible mode for a progress spinner. */
@@ -128,12 +128,16 @@ export class MatProgressSpinner {
128128

129129
constructor() {
130130
const defaults = inject<MatProgressSpinnerDefaultOptions>(MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS);
131+
const animationsState = _getAnimationsState();
132+
const element = this._elementRef.nativeElement;
131133

132-
this._noopAnimations = _animationsDisabled() && !!defaults && !defaults._forceAnimations;
133-
this.mode =
134-
this._elementRef.nativeElement.nodeName.toLowerCase() === 'mat-spinner'
135-
? 'indeterminate'
136-
: 'determinate';
134+
this._noopAnimations =
135+
animationsState === 'di-disabled' && !!defaults && !defaults._forceAnimations;
136+
this.mode = element.nodeName.toLowerCase() === 'mat-spinner' ? 'indeterminate' : 'determinate';
137+
138+
if (!this._noopAnimations && animationsState === 'reduced-motion') {
139+
element.classList.add('mat-progress-spinner-reduced-motion');
140+
}
137141

138142
if (defaults) {
139143
if (defaults.color) {

0 commit comments

Comments
 (0)