Merge pull request #4456 from ethereum/yann300-patch-54

Fix handling modal blur
pull/4500/head
yann300 10 months ago committed by GitHub
commit 0a5efa2b0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx

@ -26,24 +26,25 @@ export const ModalDialog = (props: ModalDialogProps) => {
useEffect(() => {
calledHideFunctionOnce.current = props.hide
modal.current.focus()
}, [props.hide])
useEffect(() => {
function handleBlur(e) {
if (!e.currentTarget.contains(e.relatedTarget)) {
e.stopPropagation()
if (document.activeElement !== this) {
!window.testmode && handleHide()
}
}
}
if (modal.current) {
modal.current.removeEventListener('blur', handleBlur)
modal.current.addEventListener('blur', handleBlur)
}
return () => {
modal.current && modal.current.removeEventListener('blur', handleBlur)
}
}, [modal.current])
}, [props.hide])
function handleBlur(e) {
if (!e.currentTarget.contains(e.relatedTarget)) {
e.stopPropagation()
if (document.activeElement !== this) {
!window.testmode && handleHide()
!window.testmode && props.cancelFn && props.cancelFn()
}
}
}
const modalKeyEvent = (keyCode) => {
if (keyCode === 27) {

Loading…
Cancel
Save