Skip to content

Commit 5842034

Browse files
committed
fix(ui-file-drop): fix files and value prop empty when adding a file via drag and drop
Browsers dont populate this field by default, one needs to do via JS INSTUI-4476
1 parent 9c257f4 commit 5842034

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/ui-file-drop/src/FileDrop/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
231231
const [accepted, rejected] = this.parseFiles(fileList)
232232
e.preventDefault()
233233
this.enterCounter = 0
234+
// When dropping a file the browser does not populate the input's
235+
// 'files' property, so we need to do it manually. This will also populate
236+
// the input's 'value' prop, which contains the first file's path
237+
if (accepted.length > 0 && 'dataTransfer' in e) {
238+
this.fileInputEl!.files = e.dataTransfer!.files
239+
}
234240
onDrop && onDrop(accepted, rejected, e as React.DragEvent)
235241
if (rejected.length > 0 && onDropRejected) {
236242
onDropRejected(rejected, e)

0 commit comments

Comments
 (0)