diff --git a/src/components/PopupModal/PopupModal.tsx b/src/components/PopupModal/PopupModal.tsx index dbe91a329..44f0bb06c 100644 --- a/src/components/PopupModal/PopupModal.tsx +++ b/src/components/PopupModal/PopupModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import ReactDOM from 'react-dom'; import { useTranslation } from 'react-i18next'; @@ -36,6 +36,22 @@ const PopupModal = ({ else _handleClose(); }; + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') { + if (handleClickBackdrop) handleClickBackdrop(); + else handleClose ? handleClose() : setIsModalOpen(false); + } else if (event.key === 'Enter') { + if (handleConfirm) handleConfirm(); + } + }; + + useEffect(() => { + document.addEventListener('keydown', handleKeyDown); + return () => { + document.removeEventListener('keydown', handleKeyDown); + }; + }, []); + if (modalRoot) { return ReactDOM.createPortal(