FileField
A file field, composed from a trigger, a dropzone and the list of chosen files.
Import
Copy code
import { FileField } from '@k8ordo/ui';Usage
Copy code
<FileField.Root accept="image/*" multiple={false}>
<FileField.Trigger
renderItem={({ disabled, onClick }) => (
<Button disabled={disabled} onClick={onClick}>
Select File
</Button>
)}
/>
<FileField.ItemList clearable />
</FileField.Root>Adding files by drop
Files dropped on FileField.Dropzone join the list and the submission just as picked ones do, and an input event tells the form. Left empty, it holds the built-in hint and a choose-files button, so it works by keyboard too. A dropped folder is not accepted. The browser checks accept only for files chosen in the picker, so FileField checks dropped files by the same rules and leaves out any that do not match.
Drop files here
Copy code
<FileField.Root accept="image/*" multiple>
<FileField.Dropzone />
<FileField.ItemList clearable />
</FileField.Root>Accepted types
Copy code
{/* Accept only PDF and Word documents */}
<FileField.Root accept=".pdf,.doc,.docx" multiple={false}>
<FileField.Trigger
renderItem={({ disabled, onClick }) => (
<Button disabled={disabled} onClick={onClick}>
Select Document
</Button>
)}
/>
<FileField.ItemList clearable />
</FileField.Root>Multiple files
Copy code
<FileField.Root maxFiles={3} multiple>
<FileField.Trigger
renderItem={({ disabled, onClick }) => (
<Button disabled={disabled} onClick={onClick}>
Select Files (max 3)
</Button>
)}
/>
<FileField.ItemList clearable />
</FileField.Root>Disabled
Copy code
<FileField.Root disabled multiple={false}>
<FileField.Trigger
renderItem={({ disabled, onClick }) => (
<Button disabled={disabled} onClick={onClick}>
Select File
</Button>
)}
/>
<FileField.ItemList clearable />
</FileField.Root>Invalid
Copy code
<FileField.Root invalid multiple={false}>
<FileField.Trigger
renderItem={({ disabled, onClick }) => (
<Button disabled={disabled} onClick={onClick}>
Select File
</Button>
)}
/>
<FileField.ItemList clearable />
</FileField.Root>Props
FileField.Root
children?- Type:
ReactNode - Default: -
defaultValue?- Type:
File[]|string - Default: -
invalid?- Type:
boolean - Default:
false maxFiles?- Type:
number - Default: -
onChange?- Type:
(files: FileList | null, event?: ChangeEvent<HTMLInputElement>) => void - Default: -
ref?- Type:
Ref<HTMLInputElement> - Default: -
webkitDirectory?- Type:
boolean - Default:
false
| Prop | Type | Default |
|---|---|---|
children? | ReactNode | - |
defaultValue? | File[]|string | - |
invalid? | boolean | false |
maxFiles? | number | - |
onChange? | (files: FileList | null, event?: ChangeEvent<HTMLInputElement>) => void | - |
ref? | Ref<HTMLInputElement> | - |
webkitDirectory? | boolean | false |
Inherited attributes (except the ones set internally): InputHTMLAttributes<HTMLInputElement>
FileField.Trigger
renderItem- Type:
(props: { onClick: () => void; disabled: boolean; invalid: boolean; }) => ReactElement - Default: -
| Prop | Type | Default |
|---|---|---|
renderItem | (props: { onClick: () => void; disabled: boolean; invalid: boolean; }) => ReactElement | - |
FileField.ItemList
clearable?- Type:
boolean - Default: -
showWebkitRelativePath?- Type:
boolean - Default: -
| Prop | Type | Default |
|---|---|---|
clearable? | boolean | - |
showWebkitRelativePath? | boolean | - |