Skip to content

Commit

Permalink
🩹 Prevent page scroll when Up/Down arrow is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
satnaing committed Oct 22, 2022
1 parent 6a0bfb9 commit 9317952
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ function App() {
const { theme, themeLoaded, setMode } = useTheme();
const [selectedTheme, setSelectedTheme] = useState(theme);

// Disable browser's default behavior
// to prevent the page go up when Up Arrow is pressed
useEffect(() => {
window.addEventListener(
"keydown",
e => {
["ArrowUp", "ArrowDown"].indexOf(e.code) > -1 && e.preventDefault();
},
false
);
}, []);

useEffect(() => {
setSelectedTheme(theme);
}, [themeLoaded]);
Expand Down

0 comments on commit 9317952

Please sign in to comment.