handling inclosable param

This commit is contained in:
Antoine M 2024-05-14 17:00:27 +02:00
parent ae438fb89f
commit 8b2fd1ca50

View File

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
export default function Modal({ open, onClose, children, className, id, closeModal }) { export default function Modal({ open, onClose, children, className, id, closeModal, unclosable }) {
const modalRef = useRef(null); const modalRef = useRef(null);
useEffect(() => { useEffect(() => {
@ -15,6 +15,14 @@ export default function Modal({ open, onClose, children, className, id, closeMod
else el.close(); else el.close();
}, [open]); }, [open]);
useEffect(() => {
if (!unclosable) return;
const { current: currentElement } = modalRef;
currentElement.addEventListener("cancel", (event) => {
event.preventDefault();
});
}, [unclosable]);
return ( return (
<dialog id={id} className={className} ref={modalRef} onClose={onClose}> <dialog id={id} className={className} ref={modalRef} onClose={onClose}>
{children} {children}