Skip to content

Commit

Permalink
Merge pull request #4140 from marmelab/fix-fileinput-ondrop
Browse files Browse the repository at this point in the history
Fix FileInput onDrop option
  • Loading branch information
fzaninotto authored Dec 11, 2019
2 parents 93f653a + 13fd095 commit 5f9a2f2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/ra-ui-materialui/src/input/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ const FileInput: FunctionComponent<
const { touched, error } = meta;
const files = value ? (Array.isArray(value) ? value : [value]) : [];

const onDrop = newFiles => {
const onDrop = (newFiles, rejectedFiles, event) => {
const updatedFiles = multiple ? [...files, ...newFiles] : [...newFiles];

if (multiple) {
onChange(updatedFiles);
} else {
onChange(updatedFiles[0]);
}

if (options.onDrop) {
options.onDrop(newFiles, rejectedFiles, event);
}
};

const onRemove = file => () => {
Expand All @@ -154,6 +158,7 @@ const FileInput: FunctionComponent<
multiple,
onDrop,
});

return (
<Labeled
id={id}
Expand Down

0 comments on commit 5f9a2f2

Please sign in to comment.