handling inclosable param
This commit is contained in:
parent
ae438fb89f
commit
8b2fd1ca50
|
|
@ -1,7 +1,7 @@
|
|||
import React 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);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -15,6 +15,14 @@ export default function Modal({ open, onClose, children, className, id, closeMod
|
|||
else el.close();
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!unclosable) return;
|
||||
const { current: currentElement } = modalRef;
|
||||
currentElement.addEventListener("cancel", (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
}, [unclosable]);
|
||||
|
||||
return (
|
||||
<dialog id={id} className={className} ref={modalRef} onClose={onClose}>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user