Select file or drag here
Select file or drag here
Attach up to 2 files.Button
Use the default children
slot to overwrite the default dropzone interface. Allow for a custom interface.
Disabled
Select file or drag here
Bind to API
You can optionally bind to the internal Zag component API to access additional methods such as clearFiles()
.
Select file or drag here
RTL
Select file or drag here
Additional Features
Accepted File Formats
<FileUpload accept="image/*"><FileUpload accept={"text/html": [".html", ".htm"]}>
File Validation
<FileUpload maxFiles={5}><FileUpload minFileSize={1024 * 1024 * 5}> <!-- 5 mb --><FileUpload maxFileSize={1024 * 1024 * 10}> <!-- 10 mb -->
Custom Validation
function validateFileSize(file) { if (file.size > 1024 * 1024 * 10) return ['FILE_TOO_LARGE']; return null;}
<FileUpload validate={validateFileSize} onFileReject={console.error}>
Events
<FileUpload onFileChange={console.log}> <!-- Triggers when files changed. --><FileUpload onFileAccept={console.log}> <!-- Triggers when files are accepted. --><FileUpload onFileReject={console.error}> <!-- Triggers when files are rejected. -->
Image Previews
function generatePreview(event) { const reader = new FileReader(); reader.onload = (event) => { const image = event.target.result; // set the image as the src of an image element }; reader.readAsDataURL(event.details.acceptedFiles[0]);}
<FileUpload onFileChange={generatePreview}>
Miscellaneous
<FileUpload allowDrop> <!-- Enable drag-and-drop --><FileUpload directory> <!-- Enable directories --><FileUpload capture> <!-- Enable media capture on mobile devices -->
API Reference
FileUpload
Property | Type | Description |
---|---|---|
label | string | |
subtext | string | |
base | string | |
classes | string | |
interfaceBase | string | |
interfaceBg | string | |
interfaceBorder | string | |
interfaceBorderColor | string | |
interfacePadding | string | |
interfaceRounded | string | |
interfaceClasses | string | |
interfaceIcon | string | |
interfaceText | string | |
interfaceSubtext | string | |
filesListBase | string | |
filesListClasses | string | |
fileBase | string | |
fileBg | string | |
fileGap | string | |
filePadding | string | |
fileRounded | string | |
fileClasses | string | |
fileIcon | string | |
fileName | string | |
fileSize | string | |
fileButton | string | |
stateDisabled | string | |
stateInvalid | string | |
stateDragging | string | |
children | Snippet<[]> | |
iconInterface | Snippet<[]> | |
iconFile | Snippet<[]> | |
iconFileRemove | Snippet<[]> | |
internalApi | FileUploadApi | |
name | string | |
ids | 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; }> | |
translations | IntlTranslations | |
accept | Record<string, string[]> | FileMimeType | FileMimeType[] | |
disabled | boolean | |
required | boolean | |
allowDrop | boolean | |
maxFileSize | number | |
minFileSize | number | |
maxFiles | number | |
validate | (file: File, details: FileValidateDetails) => FileError[] | |
onFileChange | (details: FileChangeDetails) => void | |
onFileAccept | (details: FileAcceptDetails) => void | |
onFileReject | (details: FileRejectDetails) => void | |
capture | "user" | "environment" | |
directory | boolean | |
invalid | boolean | |
locale | string | |
dir | "ltr" | "rtl" | |
getRootNode | () => ShadowRoot | Node | Document | |