mirror of
https://github.com/mediacms-io/mediacms.git
synced 2024-11-24 17:24:43 +01:00
add esc key
This commit is contained in:
parent
103eb01d7f
commit
6a86bda0ab
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user