Skip to content

Commit 20996aa

Browse files
committed
fix canceling tx on blur
1 parent 2cd7eb8 commit 20996aa

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ export const ModalDialog = (props: ModalDialogProps) => {
2626
useEffect(() => {
2727
calledHideFunctionOnce.current = props.hide
2828
modal.current.focus()
29-
}, [props.hide])
3029

31-
useEffect(() => {
32-
function handleBlur(e) {
33-
if (!e.currentTarget.contains(e.relatedTarget)) {
34-
e.stopPropagation()
35-
if (document.activeElement !== this) {
36-
!window.testmode && handleHide()
37-
if (props.cancelFn) props.cancelFn()
38-
}
39-
}
40-
}
4130
if (modal.current) {
31+
modal.current.removeEventListener('blur', handleBlur)
4232
modal.current.addEventListener('blur', handleBlur)
4333
}
4434
return () => {
4535
modal.current && modal.current.removeEventListener('blur', handleBlur)
4636
}
47-
}, [modal.current])
37+
}, [props.hide])
38+
39+
function handleBlur(e) {
40+
if (!e.currentTarget.contains(e.relatedTarget)) {
41+
e.stopPropagation()
42+
if (document.activeElement !== this) {
43+
!window.testmode && handleHide()
44+
if (props.cancelFn) props.cancelFn()
45+
}
46+
}
47+
}
4848

4949
const modalKeyEvent = (keyCode) => {
5050
if (keyCode === 27) {

0 commit comments

Comments
 (0)