Skip to content

feat(material/core): handle prefers-reduced-motion automatically #30796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goldens/material/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AnimationDurations {

// @public
export interface AnimationsConfig {
animationsDisabled: boolean;
animationsDisabled?: boolean;
}

// @public
Expand Down
1 change: 1 addition & 0 deletions src/material/core/animation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ ng_project(
srcs = ["animation.ts"],
deps = [
"//:node_modules/@angular/core",
"//src/cdk/layout",
],
)
15 changes: 9 additions & 6 deletions src/material/core/animation/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {MediaMatcher} from '@angular/cdk/layout';
import {ANIMATION_MODULE_TYPE, inject, InjectionToken} from '@angular/core';

/** Object used to configure the animation in Angular Material. */
export interface AnimationsConfig {
/** Whether all animations should be disabled. */
animationsDisabled: boolean;
animationsDisabled?: boolean;
}

/** Injection token used to configure the animations in Angular Material. */
Expand Down Expand Up @@ -45,11 +46,13 @@ export class AnimationDurations {
* @docs-private
*/
export function _animationsDisabled(): boolean {
const customToken = inject(MATERIAL_ANIMATIONS, {optional: true});

if (customToken) {
return customToken.animationsDisabled;
if (
inject(MATERIAL_ANIMATIONS, {optional: true})?.animationsDisabled ||
inject(ANIMATION_MODULE_TYPE, {optional: true}) === 'NoopAnimations'
) {
return true;
}

return inject(ANIMATION_MODULE_TYPE, {optional: true}) === 'NoopAnimations';
const mediaMatcher = inject(MediaMatcher);
return mediaMatcher.matchMedia('(prefers-reduced-motion)').matches;
}
Loading