1. Documentation
  2. Forms
  3. File Upload
ReadmenpmGitHub
  • Introduction
  • Installation
  • Theming
  • Icons
  • Accordion
  • Card
  • Scroll Area
  • Separator
  • Sidebar
  • Field
  • Label
  • Input
  • Textarea
  • Number Field
  • OTP Field
  • Select
  • Combobox
  • Checkbox
  • Radio
  • Switch
  • Slider
  • Toggle
  • Calendar
  • Date Picker
  • File Upload
  • Button
  • Copy Button
  • Dropdown
  • Command
  • Tabs
  • Breadcrumb
  • Pagination
  • Tree
  • Table
  • Data Table
  • Stat
  • Timeline
  • Avatar
  • Status Bar
  • Badge
  • Meter
  • Empty
  • Skeleton
  • Spinner
  • Toast
  • Dialog
  • Sheet
  • Popover
  • Tooltip
  • Text
  • Kbd
  • Code Block
  • Utilities
  • Design rules

File Upload

A drop zone that is also a button, with a file list that tracks progress.

Loading documentation…

Date Picker< PreviousButtonNext >

Powered by heyo

On this page

UsageThe file listCopy that says what is acceptedformatBytesPropertiesUploadedFile
<FileUploadaccept="image/*,.pdf"multiplemaxSize={5 * 1024 * 1024}description="PNG, JPG or PDF up to 5 MB."onFiles={upload}/>

FileUpload is a drop zone and a button, always both: drag and drop is undiscoverable on its own and impossible on a phone. The whole zone is a <label> for a hidden file input — one element, keyboard-focusable, and the click path needs no JavaScript at all.

Usage

tsx
import { FileUpload } from "@heyo-sh/heyo-ui";<FileUpload accept="image/*" multiple onFiles={upload} />;

onFiles receives everything accepted, from both the drop and the picker, after accept and maxSize have had their say.

The file list

Hand it files and it renders the list: name, size, a progress bar while the upload runs, an error when it fails, and a remove control wired to onRemove. Leave files out and render the list yourself.

  • architecture.pdf180 kB
  • Loading
    screenshot.png96 kB
    x
  • notes.txt2.0 kB
    Unsupported type
<FileUploadmultiplefiles={[  { id: "1", name: "architecture.pdf", size: 184320, status: "done" },  { id: "2", name: "screenshot.png", size: 98304, progress: 46, status: "uploading" },  { id: "3", name: "notes.txt", size: 2048, status: "error", error: "Unsupported type" },]}onRemove={cancel}/>

A file with no progress draws no bar: undefined means "not tracking progress", which is different from zero.

Copy that says what is accepted

label is the headline inside the zone and description is the line beneath it. Put the formats and the size limit in the description — a rejection after the fact is a worse experience than a sentence before it.

<FileUploadicon={IconCloudUpload}label="Drop a certificate"description="PEM or PKCS#12, up to 1 MB."accept=".pem,.p12"maxSize={1024 * 1024}/>

formatBytes

The same helper the file list uses, exported so your own rows read identically.

tsx
import { formatBytes } from "@heyo-sh/heyo-ui";formatBytes(184320); // "180 KB"

Properties

onFiles(files: File[]) => voidoptional

Fires with everything accepted, for both the drop and the picker.

acceptstringoptional

The accept attribute of the hidden input, for example "image/*,.pdf".

multiplebooleanoptional

Allows more than one file per selection.

maxSizenumberoptional

Rejects anything larger, in bytes, before onFiles sees it.

iconIconLikeoptional

The glyph inside the zone.

labelReactNodeoptional

The headline inside the zone.

descriptionReactNodeoptional

The second line — formats, size limits.

filesUploadedFile[]optional

The list to render under the zone.

onRemove(id: string) => voidoptional

Fires when a row's remove control is used.

disabledbooleanoptional

Dims the zone and ignores drops.

UploadedFile

idstringrequired

Stable id, handed back to onRemove.

namestringrequired

The file name shown in the row.

sizenumberrequired

Size in bytes, formatted with formatBytes.

progressnumberoptional

0–100. undefined means "not tracking progress" and draws no bar.

status"pending" | "uploading" | "done" | "error"optional

Drives the row's icon and tone.

errorReactNodeoptional

The message shown under the row when the upload failed.