File Upload
A component that is used to upload multiple files.
A component that is used to upload multiple files.
Please note, the API of this component is currently in a preview phase and is subject to change.
To set up the file upload component correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-partattribute to help identify them in the DOM.
Learn how to use the FileUpload component in your project. Let’s take a look
at the most basic example:
import { FileUpload } from '@ark-ui/react'
import { FileIcon } from './icons'
const Basic = () => (
<FileUpload.Root maxFiles={5}>
<FileUpload.Label>File Upload</FileUpload.Label>
<FileUpload.Dropzone>Drag your file(s) here</FileUpload.Dropzone>
<FileUpload.Trigger>Choose file(s)</FileUpload.Trigger>
<FileUpload.ItemGroup>
{(files) =>
files.map((file, id) => (
<FileUpload.Item key={id} file={file}>
<FileUpload.ItemPreview type="image/*">
<FileUpload.ItemPreviewImage />
</FileUpload.ItemPreview>
<FileUpload.ItemPreview type=".*">
<FileIcon />
</FileUpload.ItemPreview>
<FileUpload.ItemName />
<FileUpload.ItemSizeText />
<FileUpload.ItemDeleteTrigger>X</FileUpload.ItemDeleteTrigger>
</FileUpload.Item>
))
}
</FileUpload.ItemGroup>
</FileUpload.Root>
)
import { FileUpload } from '@ark-ui/solid'
import { For } from 'solid-js'
const Basic = () => (
<FileUpload.Root maxFiles={5}>
<FileUpload.Label>File Upload</FileUpload.Label>
<FileUpload.Dropzone>Drag your file(s) here</FileUpload.Dropzone>
<FileUpload.Trigger>Choose file(s)</FileUpload.Trigger>
<FileUpload.ItemGroup>
{(files) => (
<For each={files()}>
{(file) => (
<FileUpload.Item file={file}>
<FileUpload.ItemPreview type="image/*">
<FileUpload.ItemPreviewImage />
</FileUpload.ItemPreview>
<FileUpload.ItemPreview type=".*">Any Icon</FileUpload.ItemPreview>
<FileUpload.ItemName />
<FileUpload.ItemSizeText />
<FileUpload.ItemDeleteTrigger>X</FileUpload.ItemDeleteTrigger>
</FileUpload.Item>
)}
</For>
)}
</FileUpload.ItemGroup>
</FileUpload.Root>
)
<script setup lang="ts">
import { FileUpload } from '@ark-ui/vue'
</script>
<template>
<FileUpload.Root :maxFiles="5">
<FileUpload.Dropzone>
<FileUpload.Label>Drag your file(s) here</FileUpload.Label>
</FileUpload.Dropzone>
<FileUpload.Trigger>Choose file(s)</FileUpload.Trigger>
<FileUpload.ItemGroup v-slot="files">
<FileUpload.Item v-for="file in files" :file="file" :key="file">
<FileUpload.ItemPreview type="image/*">
<FileUpload.ItemPreviewImage />
</FileUpload.ItemPreview>
<FileUpload.ItemPreview type=".*">
<div>Generic Icon</div>
</FileUpload.ItemPreview>
<FileUpload.ItemName />
<FileUpload.ItemSizeText />
<FileUpload.ItemDeleteTrigger>X</FileUpload.ItemDeleteTrigger>
</FileUpload.Item>
</FileUpload.ItemGroup>
</FileUpload.Root>
</template>
| Prop | Type | Default |
|---|---|---|
file | File | |
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
acceptThe accept file types | string | Record<string, string[]> | |
allowDropWhether to allow drag and drop in the dropzone element | boolean | |
asChildRender as a different element type. | boolean | |
dirThe document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
disabledWhether the file input is disabled | boolean | |
filesThe current value of the file input | File[] | |
getRootNodeA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
idThe unique identifier of the machine. | string | |
idsThe ids of the elements. Useful for composition. | Partial<{
root: string
dropzone: string
hiddenInput: string
trigger: string
label: string
item(id: string): string
itemName(id: string): string
itemSizeText(id: string): string
itemPreview(id: string): string
}> | |
localeThe current locale. Based on the BCP 47 definition. | string | "en-US" |
maxFilesThe maximum number of files | number | |
maxFileSizeThe maximum file size in bytes | number | |
minFileSizeThe minimum file size in bytes | number | |
nameThe name of the underlying file input | string | |
onFileAcceptFunction called when the file is accepted | (details: FileAcceptDetails) => void | |
onFileRejectFunction called when the file is rejected | (details: FileRejectDetails) => void | |
onFilesChangeFunction called when the value changes, whether accepted or rejected | (details: FileChangeDetails) => void | |
translationsThe localized messages to use. | IntlTranslations | |
validateFunction to validate a file | (file: File) => FileError[] | null |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean | |
typeThe file type to match against. Matches all file types by default. | string | '.*' |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
| Prop | Type | Default |
|---|---|---|
asChildRender as a different element type. | boolean |
Previous
EnvironmentNext
Hover Card