From 38adb72b8160b7ba14ce6d348a818a54d234db24 Mon Sep 17 00:00:00 2001 From: Gorbachev Egor <7gorbachevm@gmail.com> Date: Tue, 21 Nov 2023 12:10:31 +0700 Subject: [PATCH] Revert mac navigation fix --- src/lib/keyboard/useMacTabNavigationFix.tsx | 50 --------------------- src/screens/deck-form/deck-form.tsx | 2 - 2 files changed, 52 deletions(-) delete mode 100644 src/lib/keyboard/useMacTabNavigationFix.tsx diff --git a/src/lib/keyboard/useMacTabNavigationFix.tsx b/src/lib/keyboard/useMacTabNavigationFix.tsx deleted file mode 100644 index 56a0057d..00000000 --- a/src/lib/keyboard/useMacTabNavigationFix.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { useEffect } from "react"; - -const isMacOS = /Mac OS X/i.test(navigator.userAgent); - -// Custom hook for handling tab navigation in Safari on macOS -// It's either a bug of Telegram for Mac or some issues with Safari WebView -export const useMacTabNavigationFix = () => { - useEffect(() => { - if (!isMacOS) { - return; - } - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === "Tab") { - event.preventDefault(); - - const inputs = Array.from(document.querySelectorAll("input, textarea")); - const activeElement = document.activeElement; - // @ts-expect-error - const currentIndex = inputs.indexOf(activeElement); - if (currentIndex === -1) { - // No input is currently focused, focus the first input - if (inputs.length > 0) { - // @ts-expect-error - inputs[0].focus(); - } - } else { - if (event.shiftKey && currentIndex > 0) { - // Shift + Tab was pressed - // @ts-expect-error - inputs[currentIndex - 1].focus(); - } else if ( - !event.shiftKey && - currentIndex >= 0 && - currentIndex < inputs.length - 1 - ) { - // Only Tab was pressed - // @ts-expect-error - inputs[currentIndex + 1].focus(); - } - } - } - }; - - // Only keyup works here, events like keydown and keypress don't - document.addEventListener("keyup", handleKeyDown); - return () => { - document.removeEventListener("keyup", handleKeyDown); - }; - }, []); -}; diff --git a/src/screens/deck-form/deck-form.tsx b/src/screens/deck-form/deck-form.tsx index a32c90f0..bee8838c 100644 --- a/src/screens/deck-form/deck-form.tsx +++ b/src/screens/deck-form/deck-form.tsx @@ -12,7 +12,6 @@ import { useMount } from "../../lib/react/use-mount.ts"; import { useBackButton } from "../../lib/telegram/use-back-button.tsx"; import { useTelegramProgress } from "../../lib/telegram/use-telegram-progress.tsx"; import { assert } from "../../lib/typescript/assert.ts"; -import { useMacTabNavigationFix } from "../../lib/keyboard/useMacTabNavigationFix.tsx"; export const DeckForm = observer(() => { const deckFormStore = useDeckFormStore(); @@ -29,7 +28,6 @@ export const DeckForm = observer(() => { deckFormStore.onDeckBack(); }); useTelegramProgress(() => deckFormStore.isSending); - useMacTabNavigationFix(); if (!deckFormStore.form) { return null;