File Upload

File Upload

Forms
Media

Drag-and-drop file upload with preview, validation, and multiple file support. Features image thumbnails, file size limits, and error handling.

Preview

Single file upload with drag and drop

Variants

Dropzone and inline upload styles

Dropzone (Default)

Inline

Choose a file...

Multiple Files

Upload multiple files at once

Custom Limits

Custom file size and count limits

Disabled State

File upload in disabled state

Props

FileUpload component API reference

PropTypeDefaultDescription
onChange(files: File[]) => void—Callback when files are added/removed
labelstring—Label text above the upload area
variant'dropzone' | 'inline''dropzone'Upload style variant
acceptstring'*'Accepted file types (MIME or extensions)
multiplebooleanfalseAllow multiple file selection
maxSizenumber10485760Maximum file size in bytes (10MB)
maxFilesnumber5Maximum number of files
placeholderstring—Placeholder text (inline variant)
disabledbooleanfalseDisable the upload
classNamestring—Additional CSS classes

Usage

Import and implementation example

import { FileUpload } from '@/blocks/forms/file-upload'
export default function Example() {
const handleFilesChange = (files: File[]) => {
console.log('Files:', files)
// Upload files to server
}
return (
<>
{/* Basic single file */}
<FileUpload
label="Upload Document"
accept="image/*,.pdf"
onChange={handleFilesChange}
/>
{/* Inline variant */}
<FileUpload
variant="inline"
label="Select File"
placeholder="Choose a file..."
onChange={handleFilesChange}
/>
{/* Multiple with limits */}
<FileUpload
label="Upload Images"
accept="image/*"
multiple
maxFiles={5}
maxSize={5 * 1024 * 1024}
onChange={handleFilesChange}
/>
</>
)
}

Features

Built-in functionality

  • Drag and drop: Drop files directly on the upload area
  • File type filtering: Accept specific file types via MIME or extensions
  • File size validation: Reject files exceeding size limit
  • Image preview thumbnails: Visual preview for uploaded images
  • Individual file removal: Remove files one at a time
  • Error messages: Clear feedback for validation failures
  • Inline variant: Compact input field style

Accessibility

Accessibility considerations

ARIA Attributes

The drop zone is a button named by the label and the prompt textFile size and count limits are linked with aria-describedbyThe hidden file input is aria-hidden and not a tab stop

Keyboard Navigation

KeyAction
TabFocus the drop zone (shows a focus ring)
Enter / SpaceOpen the file picker dialog

Notes

  • Visual feedback when dragging files over drop zone
  • Error states communicated with color and text
  • File sizes displayed in human-readable format
  • Remove buttons clearly labeled for each file

Related Components