Skip to main content
  1. Docs
  2. Components
  3. Forms

File upload

Choose or drop files: a drop zone over the browser's own file input, each upload with its status.

Import
@qeetrix/react/experimental
Status
ExperimentalSince 0.0.6
Renders
<input type="file">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

file-upload.tsx
// Experimental: from the package's experimental entry, until it's stable.
import { FileUpload } from "@qeetrix/react/experimental";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
onSelect(files: File[]) => void—The files that pass accept, maxSize and multiple: upload them here.
itemsFileUploadItem[]—The files you're handling: { id, name, size, status, progress, error }.
onRemove(id: string) => void—A row's remove; without it, rows have none.
acceptstring—The types allowed: ".xml,.json" or "image/*".
maxSizenumber—The largest file, in bytes.
multiplebooleanfalseSeveral at once.
hintReactNodefrom accept and maxSizeThe line under the prompt.
locale · messages…the provider'sSizes and type lists in the locale; its words.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
file-upload<div>The root.
file-upload-zone<label>The drop zone.
file-upload-input<input type="file">The input; a Field labels it.
file-upload-list<ul>The files.
file-upload-item<li>A file and its status.

04

Report each upload

Add the file as uploading, update its progress, then done or error.

metadata.tsx
const [items, setItems] = useState<FileUploadItem[]>([]);

const upload = (files: File[]) =>
  files.forEach(async (file) => {
    const id = crypto.randomUUID();
    setItems((all) => [...all, { id, name: file.name, size: file.size, status: "uploading" }]);
    const result = await uploadMetadata(file);
    setItems((all) => all.map((item) => (item.id === id ? { ...item, ...result } : item)));
  });
Next — File uploadAccessibility