Todae

Todae

File upload

A recipe, not a package namespace. A native <input type="file"> is the control, useDropzone adds drag and drop and file checks, and your code owns the upload. There is no FileUpload.* export.

On this page

Images

The label is the drop target, so a click anywhere on it opens the picker and its text names the input. Rejected files are listed in an ErrorMessage.Root that the input's aria-describedby points to, and the input gets aria-invalid. Accepted files are listed below it.

import {
  Description,
  ErrorMessage,
  Stack,
  Text,
  useDropzone,
  type FileRejection,
  type FileRejectionReason,
} from '@tounsoo/todae';
import { useId, useState } from 'react';

const MAX_SIZE = 2_000_000;

const REASONS: Record<FileRejectionReason, string> = {
  type: 'is not an image',
  'too-large': 'is over 2 MB',
  'too-small': 'is empty',
  'too-many': 'is past the 3 file limit',
};
Up to 3 images, 2 MB each.

Style the drop state with [data-dragging] or the dragging value. Errors are not announced when they appear; use useAnnouncer if they need to be.

Uploading

Send the files from onFiles, or leave them in the input and let the form submit them: the input holds only the accepted files. Show progress with Progress.Root, as on the Progress page.

Accessible composition

Todae handles: useDropzone keeps the native <input type="file"> as the control, so its role, the keyboard and the picker come from the browser. getInputProps() sets type, accept, multiple and disabled, and getRootProps() adds only drag handlers, a paste handler with paste, and data-dragging. After the checks, the input holds only the accepted files. The hook sets no ARIA and announces nothing.

You supply: What the recipe's markup does: the <label> text that names the input, a hint joined with aria-describedby, rejection reasons written out in words, aria-invalid and the ErrorMessage.Root id added to aria-describedby when files are rejected, and a labelled list of the accepted files. An announcement of rejections, if they must be heard. Upload progress and results in text, such as a <progress> with a label.

Watch for: Hiding the input with display: none or hidden to style the drop target: dragging is pointer-only, so keyboard and screen reader users lose the only way in. Keep it focusable and show its focus. An aria-describedby that still points at an ErrorMessage.Root you no longer render. Errors shown by a red border alone.

When to use

When: A form that takes files, picked or dropped, with checks on type, size and count.

When not: Files attached to a chat message → Composer and Attachment. A picker with no drop target and no checks → <input type="file"> alone.