mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 16:25:51 +01:00
fix(modal): event leak for onHidden
This commit is contained in:
@@ -71,23 +71,25 @@ export default function Modal({ children, className, size, title, header, footer
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const modalElement = modalRef.current;
|
const modalElement = modalRef.current;
|
||||||
if (!modalElement) {
|
if (!modalElement) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (onShown) {
|
if (onShown) {
|
||||||
modalElement.addEventListener("shown.bs.modal", onShown);
|
modalElement.addEventListener("shown.bs.modal", onShown);
|
||||||
}
|
}
|
||||||
modalElement.addEventListener("hidden.bs.modal", () => {
|
|
||||||
|
function onModalHidden() {
|
||||||
onHidden();
|
onHidden();
|
||||||
if (elementToFocus.current && "focus" in elementToFocus.current) {
|
if (elementToFocus.current && "focus" in elementToFocus.current) {
|
||||||
(elementToFocus.current as HTMLElement).focus();
|
(elementToFocus.current as HTMLElement).focus();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
modalElement.addEventListener("hidden.bs.modal", onModalHidden);
|
||||||
return () => {
|
return () => {
|
||||||
if (onShown) {
|
if (onShown) {
|
||||||
modalElement.removeEventListener("shown.bs.modal", onShown);
|
modalElement.removeEventListener("shown.bs.modal", onShown);
|
||||||
}
|
}
|
||||||
modalElement.removeEventListener("hidden.bs.modal", onHidden);
|
modalElement.removeEventListener("hidden.bs.modal", onModalHidden);
|
||||||
};
|
};
|
||||||
}, [ onShown, onHidden ]);
|
}, [ onShown, onHidden ]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user