fix: "No modifications allowed" error on file drag in Firefox

This commit is contained in:
Aman Harwara
2022-11-03 19:00:34 +05:30
parent 9ae0ce0bfd
commit de4adca059

View File

@@ -100,6 +100,20 @@ const FileDragNDropProvider = ({ application, children, featuresController, file
[application], [application],
) )
const handleDragStart = useCallback(
(event: DragEvent) => {
if (isHandlingFileDrag(event, application)) {
event.preventDefault()
event.stopPropagation()
if (event.dataTransfer) {
event.dataTransfer.clearData()
}
}
},
[application],
)
const handleDragIn = useCallback( const handleDragIn = useCallback(
(event: DragEvent) => { (event: DragEvent) => {
if (!isHandlingFileDrag(event, application)) { if (!isHandlingFileDrag(event, application)) {
@@ -200,7 +214,6 @@ const FileDragNDropProvider = ({ application, children, featuresController, file
} }
}) })
event.dataTransfer.clearData()
dragCounter.current = 0 dragCounter.current = 0
} }
}, },
@@ -208,18 +221,20 @@ const FileDragNDropProvider = ({ application, children, featuresController, file
) )
useEffect(() => { useEffect(() => {
window.addEventListener('dragstart', handleDragStart)
window.addEventListener('dragenter', handleDragIn) window.addEventListener('dragenter', handleDragIn)
window.addEventListener('dragleave', handleDragOut) window.addEventListener('dragleave', handleDragOut)
window.addEventListener('dragover', handleDrag) window.addEventListener('dragover', handleDrag)
window.addEventListener('drop', handleDrop) window.addEventListener('drop', handleDrop)
return () => { return () => {
window.removeEventListener('dragstart', handleDragStart)
window.removeEventListener('dragenter', handleDragIn) window.removeEventListener('dragenter', handleDragIn)
window.removeEventListener('dragleave', handleDragOut) window.removeEventListener('dragleave', handleDragOut)
window.removeEventListener('dragover', handleDrag) window.removeEventListener('dragover', handleDrag)
window.removeEventListener('drop', handleDrop) window.removeEventListener('drop', handleDrop)
} }
}, [handleDragIn, handleDrop, handleDrag, handleDragOut]) }, [handleDragIn, handleDrop, handleDrag, handleDragOut, handleDragStart])
const contextValue = useMemo(() => { const contextValue = useMemo(() => {
return { return {