Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-pigs-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@uppy/components": patch
---

Dropzone and FileInput inherit restrictions from @uppy/core
21 changes: 15 additions & 6 deletions packages/@uppy/components/src/hooks/dropzone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DropzoneReturn<DragEventType, ChangeEventType> = {
id: string
type: 'file'
multiple: boolean
accept?: string
onChange: (event: ChangeEventType) => void
}
}
Expand Down Expand Up @@ -117,11 +118,19 @@ export function createDropzone<
onClick: handleClick,
onKeyPress: handleKeyPress,
}),
getInputProps: () => ({
id: fileInputId,
type: 'file',
multiple: true,
onChange: handleFileInputChange,
}),
getInputProps: () => {
const { restrictions } = ctx.uppy.opts
const { allowedFileTypes } = restrictions
return {
id: fileInputId,
type: 'file' as const,
multiple: restrictions.maxNumberOfFiles !== 1,
accept:
Array.isArray(allowedFileTypes) && allowedFileTypes.length > 0
? allowedFileTypes.join(', ')
: undefined,
onChange: handleFileInputChange,
}
},
}
}
27 changes: 20 additions & 7 deletions packages/@uppy/components/src/hooks/file-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,26 @@ export function createFileInput<EventType extends Event>(
}

return {
getInputProps: () => ({
id: fileInputId,
type: 'file',
multiple: props.multiple ?? true,
accept: props.accept,
onChange: handleFileInputChange,
}),
getInputProps: () => {
const { restrictions } = ctx.uppy.opts
const { allowedFileTypes, maxNumberOfFiles } = restrictions
const accept =
props.accept ??
(Array.isArray(allowedFileTypes) && allowedFileTypes.length > 0
? allowedFileTypes.join(', ')
: undefined)
const multiple =
typeof props.multiple === 'boolean'
? props.multiple
: maxNumberOfFiles !== 1
return {
id: fileInputId,
type: 'file' as const,
multiple,
accept,
onChange: handleFileInputChange,
}
},
getButtonProps: () => ({
type: 'button',
onClick: handleClick,
Expand Down