-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Router allow go back, add router history - Fix tab navigation in MacOS client
- Loading branch information
Showing
30 changed files
with
262 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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); | ||
}; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.