diff --git a/src/client/webapp/elements/require/react-helper.tsx b/src/client/webapp/elements/require/react-helper.tsx index cbd903a..fcd25a5 100644 --- a/src/client/webapp/elements/require/react-helper.tsx +++ b/src/client/webapp/elements/require/react-helper.tsx @@ -369,6 +369,7 @@ export function useActionWhenEscapeOrClickedOrContextOutsideEffect( const data = useRef< Map; mouseDownTarget: Node | null; mouseUpTarget: Node | null }> >(new Map()); + const [hadMouseDown, setHadMouseDown] = useState(false); useEffect(() => { data.current.clear(); @@ -380,7 +381,7 @@ export function useActionWhenEscapeOrClickedOrContextOutsideEffect( const handleClickOutside = useCallback( (event: MouseEvent) => { - //console.log('current:', ref.current, 'target:', event.target, 'mouseDownTarget:', mouseRef.current.mouseDownTarget, 'mouseUpTarget:', mouseRef.current.mouseUpTarget); + if (!hadMouseDown) return; // the click event can fire during the mouse up event that spawns the element that uses this hook for (const [_idx, { ref, mouseDownTarget, mouseUpTarget }] of data.current) { if (!ref.current) return; @@ -393,11 +394,11 @@ export function useActionWhenEscapeOrClickedOrContextOutsideEffect( actionFunc(); }, - [actionFunc], + [hadMouseDown, actionFunc], ); const handleMouseDown = useCallback((event: MouseEvent) => { - //console.log('mouse down. Contains: ' + ref.current.contains(event.target as Node)); + setHadMouseDown(true); for (const [_idx, dataElement] of data.current) { if (!dataElement.ref.current) return; if (dataElement.ref.current.contains(event.target as Node)) { @@ -409,7 +410,6 @@ export function useActionWhenEscapeOrClickedOrContextOutsideEffect( }, []); const handleMouseUp = useCallback((event: MouseEvent) => { - //console.log('mouse up. Contains: ' + ref.current.contains(event.target as Node)); for (const [_idx, dataElement] of data.current) { if (!dataElement.ref.current) return; if (dataElement.ref.current.contains(event.target as Node)) { diff --git a/src/client/webapp/elements/root.tsx b/src/client/webapp/elements/root.tsx index f617cfb..255be86 100644 --- a/src/client/webapp/elements/root.tsx +++ b/src/client/webapp/elements/root.tsx @@ -5,7 +5,7 @@ import App from './app'; const RootElement: FC = () => { useInitRecoil(); - return + return ; }; export default RootElement;