Skip to content

Commit 142e97a

Browse files
authored
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
1 parent bcd8856 commit 142e97a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

web/src/components/PreviewImageDialog.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
9494
}
9595
};
9696

97+
const handleImageContainerKeyDown = (event: KeyboardEvent) => {
98+
if (event.key == "ArrowLeft") {
99+
showPrevImg();
100+
} else if (event.key == "ArrowRight") {
101+
showNextImg();
102+
}
103+
};
104+
97105
const handleImgContainerScroll = (event: React.WheelEvent) => {
98106
const offsetX = event.nativeEvent.offsetX;
99107
const offsetY = event.nativeEvent.offsetY;
@@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
137145
setViewportScalable();
138146
}, []);
139147

148+
useEffect(() => {
149+
document.addEventListener("keydown", handleImageContainerKeyDown);
150+
return () => {
151+
document.removeEventListener("keydown", handleImageContainerKeyDown);
152+
};
153+
}, [currentIndex]);
154+
140155
return (
141156
<>
142157
<div className="btns-container">

0 commit comments

Comments
 (0)