Skip to content

Commit 30bee8b

Browse files
authored
Merge pull request marmelab#10402 from marmelab/fix-FileInput-onChange
Fix `<FileInput>` triggers `onChange` twice with latest version of `react-dropzone`
2 parents 8c6932f + fbf8a86 commit 30bee8b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/ra-ui-materialui/src/input/FileInput.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ export const CustomRemoveIcon = () => (
114114
</Wrapper>
115115
);
116116

117+
export const OnChange = ({ onChange = console.log }) => (
118+
<Wrapper>
119+
<FileInput source="attachment" onChange={onChange}>
120+
<FileField source="src" title="title" />
121+
</FileInput>
122+
<FormInspector name="attachment" />
123+
</Wrapper>
124+
);
125+
126+
export const OnChangeMultiple = ({ onChange = console.log }) => (
127+
<Wrapper>
128+
<FileInput source="attachment" onChange={onChange} multiple>
129+
<FileField source="src" title="title" />
130+
</FileInput>
131+
<FormInspector name="attachment" />
132+
</Wrapper>
133+
);
134+
117135
const i18nProvider = polyglotI18nProvider(() => englishMessages);
118136

119137
const Wrapper = ({ children }) => (

packages/ra-ui-materialui/src/input/FileInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const FileInput = (props: FileInputProps) => {
4040
labelMultiple = 'ra.input.file.upload_several',
4141
labelSingle = 'ra.input.file.upload_single',
4242
options = {},
43+
onChange: onChangeProp,
4344
onRemove: onRemoveProp,
4445
parse,
4546
placeholder,
@@ -95,6 +96,7 @@ export const FileInput = (props: FileInputProps) => {
9596
validate,
9697
disabled,
9798
readOnly,
99+
onChange: onChangeProp,
98100
...rest,
99101
});
100102
const { error, invalid } = fieldState;

0 commit comments

Comments
 (0)