fix overlays
This commit is contained in:
parent
140a640865
commit
aa90edb142
@ -369,6 +369,7 @@ export function useActionWhenEscapeOrClickedOrContextOutsideEffect(
|
||||
const data = useRef<
|
||||
Map<number, { ref: RefObject<HTMLElement>; mouseDownTarget: Node | null; mouseUpTarget: Node | null }>
|
||||
>(new Map());
|
||||
const [hadMouseDown, setHadMouseDown] = useState<boolean>(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)) {
|
||||
|
@ -5,7 +5,7 @@ import App from './app';
|
||||
const RootElement: FC = () => {
|
||||
useInitRecoil();
|
||||
|
||||
return <App />
|
||||
return <App />;
|
||||
};
|
||||
|
||||
export default RootElement;
|
||||
|
Loading…
Reference in New Issue
Block a user