Skip to content

Commit

Permalink
[@mantine/dropzone] Fix Dropzone.Fullscreen not disappearing when mou…
Browse files Browse the repository at this point in the history
…se is moved slowly outside its wrapper (#2305)

* [@mantine/dropzone] Dropzone.FullScreen: fixed not disappearing when mouse is moved slowly outside the wrapper

* [@mantine/dropzone] removed unused property
  • Loading branch information
Madscientiste committed Sep 3, 2022
1 parent 63278c1 commit b119f68
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/mantine-dropzone/src/DropzoneFullScreen.tsx
Expand Up @@ -61,6 +61,7 @@ export const DropzoneFullScreen = forwardRef<HTMLDivElement, DropzoneFullScreenP
...others
} = useComponentDefaultProps('DropzoneFullScreen', fullScreenDefaultProps, props);

const [counter, setCounter] = React.useState(0);
const [visible, { open, close }] = useDisclosure(false);
const { classes, cx } = useFullScreenStyles(null, {
name: 'DropzoneFullScreen',
Expand All @@ -69,15 +70,30 @@ export const DropzoneFullScreen = forwardRef<HTMLDivElement, DropzoneFullScreenP
unstyled,
});

const handleDragEnter = () => {
setCounter((prev) => prev + 1);
open();
};

const handleDragLeave = () => {
setCounter((prev) => prev - 1);
};

useEffect(() => {
if (active) {
document.addEventListener('dragover', open, false);
return () => document.removeEventListener('dragover', open, false);
}
counter === 0 && close();
}, [counter]);

return undefined;
}, [active]);
useEffect(() => {
if (!active) return undefined;

document.addEventListener('dragenter', handleDragEnter, false);
document.addEventListener('dragleave', handleDragLeave, false);

return () => {
document.removeEventListener('dragover', handleDragEnter, false);
document.removeEventListener('dragleave', handleDragLeave, false);
};
}, [active]);
return (
<OptionalPortal withinPortal={withinPortal}>
<Box
Expand Down Expand Up @@ -107,7 +123,6 @@ export const DropzoneFullScreen = forwardRef<HTMLDivElement, DropzoneFullScreenP
}}
onDragLeave={(event: any) => {
onDragLeave?.(event);
close();
}}
/>
</Box>
Expand Down

0 comments on commit b119f68

Please sign in to comment.