add esc key

This commit is contained in:
aleensd 2024-11-19 10:23:51 +02:00
parent 103eb01d7f
commit 6a86bda0ab

View File

@ -61,13 +61,13 @@ export default function ImageViewer() {
}, [isModalOpen, slideshowItems]); }, [isModalOpen, slideshowItems]);
const handleKeyDown = (event) => { const handleKeyDown = (event) => {
if (event.key === 'ArrowRight') { if (event.key === 'ArrowRight') handleNext();
handleNext(); if (event.key === 'ArrowLeft') handlePrevious();
} else if (event.key === 'ArrowLeft') { if (event.key === 'Escape') onClose();
handlePrevious();
}
}; };
const onClose=()=>setIsModalOpen(false)
const handleNext = () => { const handleNext = () => {
setCurrentIndex((prevIndex) => (prevIndex + 1) % slideshowItems.length); setCurrentIndex((prevIndex) => (prevIndex + 1) % slideshowItems.length);
}; };