Unverified Commit 142e97ab authored by RoccoSmit's avatar RoccoSmit Committed by GitHub

feat: navigate image view with keyboard keys (#4116)

* Navigate images with keyboard left and right keys

* Fix linting

* Adding missing "

* Added change to incorrect branch
parent bcd88567
...@@ -94,6 +94,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }: ...@@ -94,6 +94,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
} }
}; };
const handleImageContainerKeyDown = (event: KeyboardEvent) => {
if (event.key == "ArrowLeft") {
showPrevImg();
} else if (event.key == "ArrowRight") {
showNextImg();
}
};
const handleImgContainerScroll = (event: React.WheelEvent) => { const handleImgContainerScroll = (event: React.WheelEvent) => {
const offsetX = event.nativeEvent.offsetX; const offsetX = event.nativeEvent.offsetX;
const offsetY = event.nativeEvent.offsetY; const offsetY = event.nativeEvent.offsetY;
...@@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }: ...@@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
setViewportScalable(); setViewportScalable();
}, []); }, []);
useEffect(() => {
document.addEventListener("keydown", handleImageContainerKeyDown);
return () => {
document.removeEventListener("keydown", handleImageContainerKeyDown);
};
}, [currentIndex]);
return ( return (
<> <>
<div className="btns-container"> <div className="btns-container">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment