瀏覽代碼

fix: MediaQueryList addEventListener polyfill

GyDi 2 年之前
父節點
當前提交
fd6633f536
共有 2 個文件被更改,包括 22 次插入0 次删除
  1. 1 0
      src/main.tsx
  2. 21 0
      src/utils/polyfill.ts

+ 1 - 0
src/main.tsx

@@ -1,6 +1,7 @@
 /// <reference types="vite/client" />
 /// <reference types="vite-plugin-svgr/client" />
 import "./assets/styles/index.scss";
+import "@/utils/polyfill";
 
 import React from "react";
 import ReactDOM from "react-dom";

+ 21 - 0
src/utils/polyfill.ts

@@ -0,0 +1,21 @@
+// matchMedia polyfill for macOS 10.15
+if (
+  window.MediaQueryList &&
+  !window.MediaQueryList.prototype.addEventListener
+) {
+  window.MediaQueryList.prototype.addEventListener = function (
+    name: string,
+    callback: any
+  ) {
+    this.addListener(callback);
+  };
+
+  window.MediaQueryList.prototype.removeEventListener = function (
+    name: string,
+    callback: any
+  ) {
+    this.removeListener(callback);
+  };
+}
+
+export {};