From 6a86bda0ab7493d8c70157496b60e53905d9a75f Mon Sep 17 00:00:00 2001 From: aleensd Date: Tue, 19 Nov 2024 10:23:51 +0200 Subject: [PATCH] add esc key --- .../static/js/components/media-viewer/ImageViewer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/static/js/components/media-viewer/ImageViewer.js b/frontend/src/static/js/components/media-viewer/ImageViewer.js index fa87ed5..a806ca5 100755 --- a/frontend/src/static/js/components/media-viewer/ImageViewer.js +++ b/frontend/src/static/js/components/media-viewer/ImageViewer.js @@ -52,7 +52,7 @@ export default function ImageViewer() { useEffect(() => { if (!isModalOpen) return; - + document.addEventListener('keydown', handleKeyDown); return () => { @@ -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); };