diff --git a/client/src/components/ui/Popup/index.tsx b/client/src/components/ui/Popup/index.tsx index 989e11c89cc6d033ce262a2cdf016407809e9933..ee47a7f430e3c273ca1606219259b42a82a1ad83 100644 --- a/client/src/components/ui/Popup/index.tsx +++ b/client/src/components/ui/Popup/index.tsx @@ -1,8 +1,11 @@ import { ReactNode } from 'react'; +import { createPortal } from 'react-dom'; import './popup.scss'; +const root = document.getElementById('root') ?? document.getElementsByTagName('html')[0]; + interface Props { children: ReactNode onClose: Function @@ -10,17 +13,18 @@ interface Props { export default function Popup({ children, onClose }: Props) { document.addEventListener('keydown', (e) => { - if(e.key === "Escape") { + if (e.key === "Escape") { onClose(); } }); - return ( + return createPortal( + <div className="popup-container"> <div className="popup"> {children} </div> <div className="background" onClick={() => onClose()}></div> - </div> + </div>, root ) }