Skip to content

Commit 883151b

Browse files
authored
fix(motion): respect reduced motion in createMotionComponent() (#33357)
1 parent 5ada132 commit 883151b

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: respect reduced motion in createMotionComponent()",
4+
"packageName": "@fluentui/react-motion",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-motion/library/src/contexts/MotionBehaviourContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import * as React from 'react';
66
export type MotionBehaviourType = 'skip' | 'default';
77

88
const MotionBehaviourContext = React.createContext<MotionBehaviourType | undefined>(undefined);
9+
910
export const MotionBehaviourProvider = MotionBehaviourContext.Provider;
1011
export const useMotionBehaviourContext = () => React.useContext(MotionBehaviourContext) ?? 'default';

packages/react-components/react-motion/library/src/hooks/useIsReducedMotion.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import * as React from 'react';
21
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
2+
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
3+
import * as React from 'react';
34

45
const REDUCED_MEDIA_QUERY = 'screen and (prefers-reduced-motion: reduce)';
56

@@ -12,7 +13,7 @@ export function useIsReducedMotion(): () => boolean {
1213
const queryValue = React.useRef<boolean>(false);
1314
const isEnabled = React.useCallback(() => queryValue.current, []);
1415

15-
React.useEffect(() => {
16+
useIsomorphicLayoutEffect(() => {
1617
if (targetWindow === null || typeof targetWindow.matchMedia !== 'function') {
1718
return;
1819
}

0 commit comments

Comments
 (0)