Skip to content

Commit

Permalink
support older browser with MediaQueryList
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaricBaraou committed Sep 29, 2021
1 parent 644ede5 commit b913ecf
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/A11yUserPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,35 @@ export const A11yUserPreferences: React.FC<Props> = ({ children }) => {
});
};

prefersReducedMotionMediaQuery.addEventListener(
'change',
handleReducedMotionPrefChange
);
prefersDarkSchemeMediaQuery.addEventListener(
'change',
handleDarkSchemePrefChange
);
return () => {
prefersReducedMotionMediaQuery.removeEventListener(
if (typeof prefersReducedMotionMediaQuery.addEventListener === 'function') {
prefersReducedMotionMediaQuery.addEventListener(
'change',
handleReducedMotionPrefChange
);
prefersDarkSchemeMediaQuery.removeEventListener(
}
if (typeof prefersDarkSchemeMediaQuery.addEventListener === 'function') {
prefersDarkSchemeMediaQuery.addEventListener(
'change',
handleDarkSchemePrefChange
);
}
return () => {
if (
typeof prefersReducedMotionMediaQuery.removeEventListener === 'function'
) {
prefersReducedMotionMediaQuery.removeEventListener(
'change',
handleReducedMotionPrefChange
);
}
if (
typeof prefersDarkSchemeMediaQuery.removeEventListener === 'function'
) {
prefersDarkSchemeMediaQuery.removeEventListener(
'change',
handleDarkSchemePrefChange
);
}
};
}, []);

Expand Down

0 comments on commit b913ecf

Please sign in to comment.