Skip to content

Commit

Permalink
add esc key
Browse files Browse the repository at this point in the history
  • Loading branch information
aleensd committed Nov 19, 2024
1 parent 7589d23 commit 2c3d355
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/src/static/js/components/media-viewer/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function ImageViewer() {

useEffect(() => {
if (!isModalOpen) return;

document.addEventListener('keydown', handleKeyDown);

return () => {
Expand All @@ -61,13 +61,13 @@ export default function ImageViewer() {
}, [isModalOpen, slideshowItems]);

const handleKeyDown = (event) => {
if (event.key === 'ArrowRight') {
handleNext();
} else if (event.key === 'ArrowLeft') {
handlePrevious();
}
if (event.key === 'ArrowRight') handleNext();
if (event.key === 'ArrowLeft') handlePrevious();
if (event.key === 'Escape') onClose();
};

const onClose=()=>setIsModalOpen(false)

const handleNext = () => {
setCurrentIndex((prevIndex) => (prevIndex + 1) % slideshowItems.length);
};
Expand Down

0 comments on commit 2c3d355

Please sign in to comment.