mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Add itch.io scrolling protection
This commit is contained in:
parent
91dfb63fbd
commit
f944f35b61
|
@ -4,6 +4,7 @@ import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings";
|
||||||
import { styled } from "styled-components";
|
import { styled } from "styled-components";
|
||||||
import { useOnKeyUp } from "./useOnKeyUp.hook";
|
import { useOnKeyUp } from "./useOnKeyUp.hook";
|
||||||
import { useLocalStorage } from "./useLocalStorage.hook";
|
import { useLocalStorage } from "./useLocalStorage.hook";
|
||||||
|
import { useAvoidItchIoScrolling } from "./useAvoidItchIoScrolling";
|
||||||
|
|
||||||
const BindingsDialog = styled.dialog`
|
const BindingsDialog = styled.dialog`
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
@ -47,6 +48,8 @@ function App() {
|
||||||
setShowBindings(!showBindings);
|
setShowBindings(!showBindings);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useAvoidItchIoScrolling();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppContainer>
|
<AppContainer>
|
||||||
{showBindings && (
|
{showBindings && (
|
||||||
|
|
17
website/src/useAvoidItchIoScrolling.ts
Normal file
17
website/src/useAvoidItchIoScrolling.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export const useAvoidItchIoScrolling = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
const eventHandler = (e: KeyboardEvent) => {
|
||||||
|
if ([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", eventHandler, false);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", eventHandler, false);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
};
|
Loading…
Reference in a new issue