Skip to content
GitHub (opens in a new tab)

FileUpload

A drop zone with a Choose files button and a list of file rows with their progress.

stableMoleculecontracts/fileupload.json

Preview

FileUpload

A Choose files Button in a dashed drop zone, or on its own in the compact variant, plus file rows with progress, done, and error. Presentational: the app does the upload and passes the state back. Rows compose kit Progress and Button. Not Dropzone or FileInput.

Master

Pick or drop files. A timer fakes progress here; there is no network. The error row retries.

or drag and dropPDF or PNG, max 10 MB, up to 5 files
  • invoice-nov-2026.pdf1.8 MBComplete
  • statement-q3.csv12.0 MBOver the 10 MB limit

Usage

onFilesSelected hands you File objects; start the upload, then feed progress, status, and errors back through files. Choose files is a kit Button, so Tab and Enter open the picker. Drag and drop is an extra. Put the limits in maxSizeLabel so people see them before they pick.

Do's

  • Attaching files to a form, message, or record
  • Showing per-file upload progress, completion, and failures with retry
  • Inside Field when the upload needs a label, hint, or error

Don'ts

  • A single overall task percent with no file rows — use Progress
  • Choosing an avatar or image crop — not this component
  • Picking a value from a list — use Select
  • Uploading on the network — FileUpload has no fetch; the app owns the request
<FileUpload
  accept=".pdf,image/png"
  maxSizeLabel="PDF or PNG, max 10 MB, up to 5 files"
  files={files}
  onFilesSelected={startUploads}
  onRemove={removeFile}
  onRetry={retryFile}
/>

Choose files Button in a dashed drop zone (or a compact Button-only row) plus a list of file rows with progress, done, and error states. Presentational: the app does the upload; FileUpload reports picked files and renders the state it is given.

When to use

  • Attaching files to a form, message, or record
  • Showing per-file upload progress, completion, and failures with retry
  • Inside Field when the upload needs a label, hint, or error

When not to use

  • A single overall task percent with no file rows — use Progress
  • Choosing an avatar or image crop — not this component
  • Picking a value from a list — use Select
  • Uploading on the network — FileUpload has no fetch; the app owns the request

What an agent reads

import { FileUpload } from "agentic-ds-kit";
must
  • The focusable control is the kit Choose files Button, in both variants. It opens the hidden file input; Enter and Space work. Drag and drop is an enhancement, not the only path.
  • The limits line (maxSizeLabel) is linked to the Button with aria-describedby, plus Field's hint or error id
  • While files are dragged over, the zone reads 'Drop files here' in text and a brand border, not the border alone
  • error shows the danger border and Field's error text via aria-describedby; no aria-invalid on the trigger button (button does not support it)
  • The file input is hidden and out of the tab order
  • In the zone variant, keyboard focus on the Choose files Button draws one focus ring (--focus-ring at --border-focus-width) around the whole zone, and the Button's own ring is hidden
  • Each row's status text (Uploading, Complete, or the error) sits in aria-live=polite; the percent does not, so ticks are not announced
  • Uploading rows use Progress with ariaLabel 'Uploading {name}'
  • Remove Button has aria-label 'Remove {name}'; the Retry Button shows the word Retry (labels.retry) and is named 'Retry {name}' with aria-labelledby on its own id plus the file name
  • Status is never color alone: icon plus text
  • built-in labels (files, uploading, retry, removeFile) come from KitLabelsProvider; English by default
  • Error rows lead with an alert icon and show the size and message in text
defaults
  • variant zone
  • files []
  • multiple true
  • disabled false
  • error false
stops if
  • Do not invent Dropzone, FileInput, FileList, FileRow, UploadItem, or UploadProgress
  • Do not fetch or upload inside the component — the app owns the request and passes files back
  • Do not use a native progress element — rows compose kit Progress
  • Do not show a raw input type=file as the control
  • Do not use raw hex
  • Do not rely on color alone for done or error
  • Do not make the zone itself a button or put a link-styled 'Click to upload' in it — the action is the kit Choose files Button

From contracts/fileupload.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
onFilesSelectedfunctionYes—(files: File[]) => void. Called after a pick or a drop. Dropped files are filtered by accept; multiple=false keeps the first.
variantzone | compactNozonezone is the dashed drop area with a neutral sm Choose files Button, 'or drag and drop' and the limits line. compact is the Button and the limits line on one row, for drawers and tight forms. Both accept dropped files.
filesarrayNo[]{ id, name, size (bytes), progress? (0 to 100), status: 'uploading' | 'done' | 'error', error? }[]. Rows render in this order.
onRemovefunctionNo—(id) => void. When set, every row shows a remove Button (X while uploading, Trash2 after).
onRetryfunctionNo—(id) => void. When set, error rows show a labelled sm Retry Button.
acceptstringNo—Same as the input accept attribute: extensions (.pdf) and MIME types (image/*).
multiplebooleanNotrue—
maxSizeLabelstringNo—Limits line beside or under the Choose files Button, e.g. 'PDF or PNG, max 10 MB, up to 5 files'. Show it up front. Text only; the app enforces limits and reports them as row errors.
disabledbooleanNofalse—
idstringNo—Choose files Button id. Inside Field, pass the same value as htmlFor.
describedBystringNo—Set by Field (hint or error id).
errorbooleanNofalseSet by Field when it has an error. Danger border on the zone, like Input. Field's error text carries the message.
  • Component
    →

    Progress

    Task completion as a bar or circle from 0 to 100, or an indeterminate bar when the percent is not known.

  • Component
    →

    Select

    Choose one or several options from a list.