Skip to content

Commit 01b9da7

Browse files
Merge pull request #103 from ManishxNinja/feat/keyboard-navigation
feat: implement left and right arrow key navigation
2 parents c6046bd + 470f4f8 commit 01b9da7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

frontend/src/components/Media/MediaView.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ const MediaView: React.FC<MediaViewProps> = ({
1818
setGlobalIndex((currentPage - 1) * itemsPerPage + initialIndex);
1919
}, [initialIndex, currentPage, itemsPerPage]);
2020

21+
useEffect(() => {
22+
const handleKeyDown = (e: KeyboardEvent) => {
23+
if (e.key === "ArrowRight") {
24+
handleNextItem();
25+
} else if (e.key === "ArrowLeft") {
26+
handlePrevItem();
27+
}
28+
};
29+
30+
window.addEventListener("keydown", handleKeyDown);
31+
32+
return () => {
33+
window.removeEventListener("keydown", handleKeyDown);
34+
};
35+
}, [globalIndex]);
36+
2137
function handlePrevItem() {
2238
if (globalIndex > 0) {
2339
setGlobalIndex(globalIndex - 1);

0 commit comments

Comments
 (0)