import './modal.css'; import { createPortal } from 'preact/compat'; import { useEffect, useRef } from 'preact/hooks'; import { useHotkeys } from 'react-hotkeys-hook'; const $modalContainer = document.getElementById('modal-container'); function Modal({ children, onClose, onClick, class: className }) { if (!children) return null; const modalRef = useRef(); useEffect(() => { let timer = setTimeout(() => { const focusElement = modalRef.current?.querySelector('[tabindex="-1"]'); if (focusElement) { focusElement.focus(); } }, 100); return () => clearTimeout(timer); }, []); const escRef = useHotkeys('esc', onClose, [onClose], { enabled: !!onClose, }); const Modal = (