Skip to content

Commit 068c551

Browse files
Filter out empty dummy file object in from examples (#1314)
1 parent 4630125 commit 068c551

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/react/src/file-upload/file-upload.stories.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ export const Required: Story = {
101101
onSubmit={(e) => {
102102
e.preventDefault();
103103
const formData = new FormData(e.target as HTMLFormElement);
104+
const files = formData
105+
.getAll('files')
106+
.filter(
107+
(file) => file instanceof File && file.size > 0 && file.name,
108+
);
109+
104110
alert(
105-
`Lastet opp ${formData
106-
.getAll('files')
107-
.map((file) => (file as File).name)
108-
.join(', ')}`,
111+
`Lastet opp ${files.map((file) => (file as File).name).join(', ')}`,
109112
);
110113
}}
111114
>
@@ -143,17 +146,17 @@ export const InForm = () => (
143146
onSubmit={(e) => {
144147
e.preventDefault();
145148
const formData = new FormData(e.target as HTMLFormElement);
149+
const files = formData
150+
.getAll('files')
151+
.filter((file) => file instanceof File && file.size > 0 && file.name);
152+
146153
alert(
147-
`Lastet opp ${formData
148-
.getAll('files')
149-
.map((file) => (file as File).name)
150-
.join(', ')}`,
154+
`Lastet opp ${files.map((file) => (file as File).name).join(', ')}`,
151155
);
152156
}}
153157
>
154158
<FileUpload
155159
validate={(file) => file.size < 1000000 || 'Filen er for stor'}
156-
isRequired
157160
allowsMultiple
158161
name="files"
159162
>

0 commit comments

Comments
 (0)