mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
@uppy/components: inherit restrictions from @uppy/core (#6014)
Closes #5970 AI disclosure: codex made the initial implementation --------- Co-authored-by: Mikael Finstad <finstaden@gmail.com>
This commit is contained in:
parent
55e926c347
commit
26bf726412
3 changed files with 35 additions and 13 deletions
5
.changeset/nice-pigs-argue.md
Normal file
5
.changeset/nice-pigs-argue.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@uppy/components": patch
|
||||
---
|
||||
|
||||
Dropzone and FileInput inherit restrictions from @uppy/core
|
||||
|
|
@ -21,6 +21,7 @@ export type DropzoneReturn<DragEventType, ChangeEventType> = {
|
|||
id: string
|
||||
type: 'file'
|
||||
multiple: boolean
|
||||
accept?: string
|
||||
onChange: (event: ChangeEventType) => void
|
||||
}
|
||||
}
|
||||
|
|
@ -117,11 +118,17 @@ export function createDropzone<
|
|||
onClick: handleClick,
|
||||
onKeyPress: handleKeyPress,
|
||||
}),
|
||||
getInputProps: () => ({
|
||||
id: fileInputId,
|
||||
type: 'file',
|
||||
multiple: true,
|
||||
onChange: handleFileInputChange,
|
||||
}),
|
||||
getInputProps: () => {
|
||||
const { restrictions } = ctx.uppy.opts
|
||||
const accept = restrictions.allowedFileTypes?.join(', ')
|
||||
|
||||
return {
|
||||
id: fileInputId,
|
||||
type: 'file' as const,
|
||||
multiple: restrictions.maxNumberOfFiles !== 1,
|
||||
accept,
|
||||
onChange: handleFileInputChange,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,13 +49,23 @@ 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
|
||||
|
||||
let accept = props.accept
|
||||
accept ??= allowedFileTypes?.join(', ')
|
||||
let multiple = props.multiple
|
||||
multiple ??= maxNumberOfFiles !== 1
|
||||
|
||||
return {
|
||||
id: fileInputId,
|
||||
type: 'file' as const,
|
||||
multiple,
|
||||
accept,
|
||||
onChange: handleFileInputChange,
|
||||
}
|
||||
},
|
||||
getButtonProps: () => ({
|
||||
type: 'button',
|
||||
onClick: handleClick,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue