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-part
attribute 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 'lucide-react'
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 |
---|---|---|
accept The accept file types | string | Record<string, string[]> | |
allowDrop Whether to allow drag and drop in the dropzone element | boolean | |
asChild Render as a different element type. | boolean | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
disabled Whether the file input is disabled | boolean | |
files The current value of the file input | File[] | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | string | |
ids The 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
}> | |
locale The current locale. Based on the BCP 47 definition. | string | "en-US" |
maxFiles The maximum number of files | number | |
maxFileSize The maximum file size in bytes | number | |
minFileSize The minimum file size in bytes | number | |
name The name of the underlying file input | string | |
onFileAccept Function called when the file is accepted | (details: FileAcceptDetails) => void | |
onFileReject Function called when the file is rejected | (details: FileRejectDetails) => void | |
onFilesChange Function called when the value changes, whether accepted or rejected | (details: FileChangeDetails) => void | |
translations The localized messages to use. | IntlTranslations | |
validate Function to validate a file | (file: File) => FileError[] | null |
Prop | Type | Default |
---|---|---|
file | File | |
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
type The file type to match against. Matches all file types by default. | string | '.*' |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Previous
EnvironmentNext
Hover Card