From 44ecff31e3b8d6963711dd375045e5deca068fc7 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 8 Apr 2019 12:20:45 -0700 Subject: [PATCH] Fixed an unpleasant interaction with owners modal "..." button --- src/devtools/views/hooks.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/devtools/views/hooks.js b/src/devtools/views/hooks.js index 933a8097ba..3b0c064ba0 100644 --- a/src/devtools/views/hooks.js +++ b/src/devtools/views/hooks.js @@ -101,9 +101,15 @@ export function useModalDismissSignal( } }; - const handleMouseOrTouch = ({ target }: any) => { + const handleClick = (event: any) => { // $FlowFixMe - if (modalRef.current !== null && !modalRef.current.contains(target)) { + if ( + modalRef.current !== null && + !modalRef.current.contains(event.target) + ) { + event.stopPropagation(); + event.preventDefault(); + dismissCallback(); } }; @@ -113,13 +119,11 @@ export function useModalDismissSignal( // and the root document might belong to a different window. const ownerDocument = modalRef.current.ownerDocument; ownerDocument.addEventListener('keydown', handleKeyDown); - ownerDocument.addEventListener('mousedown', handleMouseOrTouch); - ownerDocument.addEventListener('touchstart', handleMouseOrTouch); + ownerDocument.addEventListener('click', handleClick); return () => { ownerDocument.removeEventListener('keydown', handleKeyDown); - ownerDocument.removeEventListener('mousedown', handleMouseOrTouch); - ownerDocument.removeEventListener('touchstart', handleMouseOrTouch); + ownerDocument.removeEventListener('click', handleClick); }; }, [modalRef, dismissCallback]); }