From aeb7617fdfa971027f78039b1694355f71463dfa Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Wed, 5 Jul 2023 13:42:38 -0700 Subject: [PATCH] fix: support both addListener and addEventListener --- src/lib/system-preferences-hoc.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/system-preferences-hoc.jsx b/src/lib/system-preferences-hoc.jsx index a67273ce8..982a761ca 100644 --- a/src/lib/system-preferences-hoc.jsx +++ b/src/lib/system-preferences-hoc.jsx @@ -17,14 +17,22 @@ const systemPreferencesHOC = function (WrappedComponent) { if (window.matchMedia) { this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery); if (this.highContrastMatchMedia) { - this.highContrastMatchMedia.addEventListener('change', this.preferencesListener); + if (this.highContrastMatchMedia.addEventListener) { + this.highContrastMatchMedia.addEventListener('change', this.preferencesListener); + } else { + this.highContrastMatchMedia.addListener(this.preferencesListener); + } } } } componentWillUnmount () { if (this.highContrastMatchMedia) { - this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener); + if (this.highContrastMatchMedia.removeEventListener) { + this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener); + } else { + this.highContrastMatchMedia.removeListener(this.preferencesListener); + } } }