Skip to content

Commit 0a5efa2

Browse files
authored
Merge pull request #4456 from ethereum/yann300-patch-54
Fix handling modal blur
2 parents ad05638 + 4985c21 commit 0a5efa2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +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-
}
38-
}
39-
}
4030
if (modal.current) {
31+
modal.current.removeEventListener('blur', handleBlur)
4132
modal.current.addEventListener('blur', handleBlur)
4233
}
4334
return () => {
4435
modal.current && modal.current.removeEventListener('blur', handleBlur)
4536
}
46-
}, [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+
!window.testmode && props.cancelFn && props.cancelFn()
45+
}
46+
}
47+
}
4748

4849
const modalKeyEvent = (keyCode) => {
4950
if (keyCode === 27) {

0 commit comments

Comments
 (0)