fix: always call preventDefault

zio/stable
Mary 2024-01-21 04:24:58 +07:00
parent 854718c555
commit 88f2a73ad6
No known key found for this signature in database
1 changed files with 12 additions and 4 deletions

View File

@ -111,24 +111,32 @@ export const TextInput = React.forwardRef(function TextInputImpl(
event.preventDefault()
setIsDropping(false)
}
const handleDragOver = (event: DragEvent) => {
const handleDragEnter = (event: DragEvent) => {
const transfer = event.dataTransfer
event.preventDefault()
if (transfer && transfer.types.includes('Files')) {
setIsDropping(true)
}
}
const handleDragLeave = (_event: DragEvent) => {
const handleDragLeave = (event: DragEvent) => {
event.preventDefault()
setIsDropping(false)
}
const handleDragOver = (event: DragEvent) => {
event.preventDefault()
}
document.body.addEventListener('drop', handleDrop)
document.body.addEventListener('dragover', handleDragOver)
document.body.addEventListener('dragenter', handleDragEnter)
document.body.addEventListener('dragleave', handleDragLeave)
document.body.addEventListener('dragover', handleDragOver)
return () => {
document.body.removeEventListener('drop', handleDrop)
document.body.removeEventListener('dragover', handleDragOver)
document.body.removeEventListener('dragenter', handleDragEnter)
document.body.removeEventListener('dragleave', handleDragLeave)
document.body.removeEventListener('dragover', handleDragOver)
}
}, [setIsDropping])