structyl

File Upload API

View component

The full prop reference for the File Upload component. A drag-and-drop file input with validation.

Import

tsx
import { FileUpload } from '@structyl/styled';

Props

Root

The main provider component that manages file state and validation; accepts all standard div HTML attributes

PropTypeDefault
asChild#boolean

Replace the root div with a child element (use Slot pattern)

value#File[]

Controlled list of currently selected files

defaultValue#File[]

Initial uncontrolled file list

[]
onValueChange#(files: File[]) => void

Callback when the file list changes (add/remove)

accept#string

Comma-separated MIME types or file extensions to accept (e.g. 'image/*' or '.pdf,.doc')

multiple#boolean

Allow selecting multiple files; if false, only one file at a time

false
maxSize#number

Maximum file size in bytes; files exceeding this trigger a 'size' error

maxFiles#number

Maximum number of files allowed; files exceeding this trigger a 'count' error

disabled#boolean

Disable file selection in Dropzone, Trigger, and Input

onError#(errors: Array<{file: File; reason: 'size' | 'type' | 'count'}>) => void

Callback for validation errors (size exceeded, type not accepted, max count exceeded)

className#string

CSS class names for custom styling

Dropzone

Drag-and-drop zone; accepts all standard div HTML attributes; features drag state data-state='dragging'|'idle' and data-disabled attribute

PropTypeDefault
className#string

CSS class names for custom styling (styled version includes sensible defaults)

children#React.ReactNode

Custom content; styled version defaults to Upload icon + descriptive text if omitted

onClick#(event: React.MouseEvent<HTMLDivElement>) => void

Triggered on click; automatically opens file picker

onDragOver#(event: React.DragEvent<HTMLDivElement>) => void

Triggered during drag; composable with internal drag state

onDragLeave#(event: React.DragEvent<HTMLDivElement>) => void

Triggered when drag leaves; composable with internal drag state

onDrop#(event: React.DragEvent<HTMLDivElement>) => void

Triggered on drop; composable with file addition

Input

Hidden file input element (type='file'); automatically receives accept and multiple from Root context; forwards standard input HTML attributes

PropTypeDefault
onChange#(event: React.ChangeEvent<HTMLInputElement>) => void

Triggered on file selection; composable with internal file addition logic

Trigger

Button to trigger file selection; automatically opens the hidden input on click; forwards standard button HTML attributes

PropTypeDefault
onClick#(event: React.MouseEvent<HTMLButtonElement>) => void

Triggered on click; composable with file picker opening

Clear

Button to clear all selected files; automatically disabled when Root.disabled is true or no files exist; forwards standard button HTML attributes

PropTypeDefault
onClick#(event: React.MouseEvent<HTMLButtonElement>) => void

Triggered on click; composable with internal clear logic

List

Container for file items (ul element); accepts all standard ul/list HTML attributes

PropTypeDefault
className#string

CSS class names for custom styling (styled version defaults to 'mt-2 space-y-1')

Item

Individual file item (li element); displays file name and size in styled version; forwards standard li HTML attributes

PropTypeDefault
file#File

Required - the File object to display; used as key and for data-file-name attribute

children#React.ReactNode

Custom content; styled version defaults to file name + size display if omitted

className#string

CSS class names for custom styling

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library