File Upload
A component that is used to upload multiple files.
A component that is used to upload multiple files.
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 { FileIcon } from 'lucide-react'
import { FileUpload } from '@ark-ui/react'
export const Basic = () => {
return (
<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>
<FileUpload.Context>
{({ acceptedFiles }) =>
acceptedFiles.map((file) => (
<FileUpload.Item key={file.name} 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.Context>
</FileUpload.ItemGroup>
<FileUpload.HiddenInput />
</FileUpload.Root>
)
}
import { For } from 'solid-js'
import { FileUpload } from '@ark-ui/solid'
export 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>
<FileUpload.Context>
{(context) => (
<For each={context().acceptedFiles}>
{(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.Context>
</FileUpload.ItemGroup>
<FileUpload.HiddenInput />
</FileUpload.Root>
)
<script setup lang="ts">
import { FileUpload } from '@ark-ui/vue'
</script>
<template>
<FileUpload.Root :maxFiles="5">
<FileUpload.Label>File Upload</FileUpload.Label>
<FileUpload.Dropzone>Drop your files here</FileUpload.Dropzone>
<FileUpload.Trigger>Choose file(s)</FileUpload.Trigger>
<FileUpload.ItemGroup>
<FileUpload.Context v-slot="{ acceptedFiles }">
<FileUpload.Item v-for="file in acceptedFiles" :file="file" :key="file.name">
<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.Context>
</FileUpload.ItemGroup>
<FileUpload.HiddenInput />
</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 | |
capture The default camera to use when capturing media | 'user' | 'environment' | |
directory Whether to accept directories, only works in webkit browsers | boolean | |
disabled Whether the file input is disabled | boolean | |
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 | |
onFileChange Function called when the value changes, whether accepted or rejected | (details: FileChangeDetails) => void | |
onFileReject Function called when the file is rejected | (details: FileRejectDetails) => void | |
translations The localized messages to use. | IntlTranslations | |
validate Function to validate a file | (file: File) => FileError[] | null |
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 |
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 |
---|---|---|
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 |
Previous
EditableNext
Hover Card