Skip to content

Commit

Permalink
Update PopupModal.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
AthanaD authored Mar 8, 2024
1 parent 884295e commit 0e02de8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/PopupModal/PopupModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -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);
};
}, [handleConfirm, handleClose, handleClickBackdrop]);

if (modalRoot) {
return ReactDOM.createPortal(
<div className='fixed top-0 left-0 z-[999] w-full p-4 overflow-x-hidden overflow-y-auto h-full flex justify-center items-center'>
Expand Down

0 comments on commit 0e02de8

Please sign in to comment.