Skip to content

Commit

Permalink
Navigate images with keyboard left and right keys
Browse files Browse the repository at this point in the history
  • Loading branch information
RoccoSmit committed Nov 10, 2024
1 parent 45d4d39 commit 0b95648
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions web/src/components/PreviewImageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
}
};

const handleImageContainerKeyDown = (event: KeyboardEvent) => {
if (event.key == "ArrowLeft") {
showPrevImg();
}

Check failure on line 100 in web/src/components/PreviewImageDialog.tsx

View workflow job for this annotation

GitHub Actions / static-checks

Delete `⏎···`
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 +146,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
setViewportScalable();
}, []);

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

Check failure on line 153 in web/src/components/PreviewImageDialog.tsx

View workflow job for this annotation

GitHub Actions / static-checks

Insert `;`
}, [currentIndex]);

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

0 comments on commit 0b95648

Please sign in to comment.