fix: support browsers that don't implement 'prefers-contrast' media query

This commit is contained in:
Christopher Willis-Ford committed 2023-07-05 09:12:31 -07:00
1 parent 1db991aa29
commit f21814b11e
1 file changed
+9 -3
+9 -3
View File
@@ -14,12 +14,18 @@ const systemPreferencesHOC = function (WrappedComponent) {
componentDidMount () {
this.preferencesListener = () => this.props.onSetTheme(detectTheme());
this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery);
this.highContrastMatchMedia.addEventListener('change', this.preferencesListener);
if (window.matchMedia) {
this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery);
if (this.highContrastMatchMedia) {
this.highContrastMatchMedia.addEventListener('change', this.preferencesListener);
}
}
}
componentWillUnmount () {
this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener);
if (this.highContrastMatchMedia) {
this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener);
}
}
render () {