Skip to content

Commit

Permalink
feat: navigate image view with keyboard keys (#4116)
Browse files Browse the repository at this point in the history
* Navigate images with keyboard left and right keys

* Fix linting

* Adding missing "

* Added change to incorrect branch
  • Loading branch information
RoccoSmit authored Nov 11, 2024
1 parent bcd8856 commit 142e97a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions web/src/components/PreviewImageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 offsetX = event.nativeEvent.offsetX;
const offsetY = event.nativeEvent.offsetY;
Expand Down Expand Up @@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
setViewportScalable();
}, []);

useEffect(() => {
document.addEventListener("keydown", handleImageContainerKeyDown);
return () => {
document.removeEventListener("keydown", handleImageContainerKeyDown);
};
}, [currentIndex]);

return (
<>
<div className="btns-container">
Expand Down

0 comments on commit 142e97a

Please sign in to comment.