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
| Prop | Type | Default | Description |
|---|---|---|---|
onChange | (files: File[]) => void | — | Callback when files are added/removed |
label | string | — | Label text above the upload area |
variant | 'dropzone' | 'inline' | 'dropzone' | Upload style variant |
accept | string | '*' | Accepted file types (MIME or extensions) |
multiple | boolean | false | Allow multiple file selection |
maxSize | number | 10485760 | Maximum file size in bytes (10MB) |
maxFiles | number | 5 | Maximum number of files |
placeholder | string | — | Placeholder text (inline variant) |
disabled | boolean | false | Disable the upload |
className | string | — | 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 stopKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the drop zone (shows a focus ring) |
| Enter / Space | Open 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