mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +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
|
id: string
|
||||||
type: 'file'
|
type: 'file'
|
||||||
multiple: boolean
|
multiple: boolean
|
||||||
|
accept?: string
|
||||||
onChange: (event: ChangeEventType) => void
|
onChange: (event: ChangeEventType) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -117,11 +118,17 @@ export function createDropzone<
|
||||||
onClick: handleClick,
|
onClick: handleClick,
|
||||||
onKeyPress: handleKeyPress,
|
onKeyPress: handleKeyPress,
|
||||||
}),
|
}),
|
||||||
getInputProps: () => ({
|
getInputProps: () => {
|
||||||
id: fileInputId,
|
const { restrictions } = ctx.uppy.opts
|
||||||
type: 'file',
|
const accept = restrictions.allowedFileTypes?.join(', ')
|
||||||
multiple: true,
|
|
||||||
onChange: handleFileInputChange,
|
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 {
|
return {
|
||||||
getInputProps: () => ({
|
getInputProps: () => {
|
||||||
id: fileInputId,
|
const { restrictions } = ctx.uppy.opts
|
||||||
type: 'file',
|
const { allowedFileTypes, maxNumberOfFiles } = restrictions
|
||||||
multiple: props.multiple ?? true,
|
|
||||||
accept: props.accept,
|
let accept = props.accept
|
||||||
onChange: handleFileInputChange,
|
accept ??= allowedFileTypes?.join(', ')
|
||||||
}),
|
let multiple = props.multiple
|
||||||
|
multiple ??= maxNumberOfFiles !== 1
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: fileInputId,
|
||||||
|
type: 'file' as const,
|
||||||
|
multiple,
|
||||||
|
accept,
|
||||||
|
onChange: handleFileInputChange,
|
||||||
|
}
|
||||||
|
},
|
||||||
getButtonProps: () => ({
|
getButtonProps: () => ({
|
||||||
type: 'button',
|
type: 'button',
|
||||||
onClick: handleClick,
|
onClick: handleClick,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue