diff --git a/web/src/components/PreviewImageDialog.tsx b/web/src/components/PreviewImageDialog.tsx index 1688400e..768ff19d 100644 --- a/web/src/components/PreviewImageDialog.tsx +++ b/web/src/components/PreviewImageDialog.tsx @@ -94,6 +94,14 @@ const PreviewImageDialog: React.FC = ({ 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; @@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC = ({ destroy, imgUrls, initialIndex }: setViewportScalable(); }, []); + useEffect(() => { + document.addEventListener("keydown", handleImageContainerKeyDown); + return () => { + document.removeEventListener("keydown", handleImageContainerKeyDown); + }; + }, [currentIndex]); + return ( <>