Skip to content

FileUpload

A file drop zone with drag and drop. It validates type and size, lists uploaded files, and lets you remove them.

Forms · TaishoDS Core, in plain HTML.

Examples

One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.

Multiple attachments with size limit

Drag files here or use the button

Attachments

Up to 2 MB per file

html

When to use

  • The user needs to upload one or more files (images, documents).
  • You want to validate type and size before accepting.
  • It helps to show what’s already uploaded and let users remove it.

When not to use

  • A minimal <input type="file"> is enough, with no list or validation.
  • It isn’t a file but a text or number value → the matching control.

Do

  • Declare the accepted types and the maximum size, and explain the limit.
  • Build it with the field markup for the label and validation errors.

Don’t

  • Don’t accept just anything. Validate type and size on the client and on the server.
  • Don’t hide the progress or the errors of a failed upload.

Related

FieldButton

TaishoDS Core

Needs Core’s JS, which hooks in through data-ts-* attributes.

It’s built on a native <input type="file"> and adds drag and drop and the file list.

Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.

  • data-ts-file-error-icon
  • data-ts-file-error-size
  • data-ts-file-input
  • data-ts-file-list
  • data-ts-file-template
  • data-ts-file-trigger
  • data-ts-file-upload
  • data-ts-max-size

What it does: Drag and drop, plus rendering the list of chosen files. With multiple, each selection is added to the list (without multiple, it replaces it), and each row has its own Remove button. Since the native input doesn’t accumulate files, Core keeps the list and rebuilds input.files with only the valid files. Each row comes from a <template data-ts-file-template> in the example. The empty list is hidden.

Attribute What it does
data-ts-file-error-sizeOn the root. The error for a file larger than data-ts-max-size, with the maximum already written in. Without it, a Spanish default message.
data-ts-file-error-typeOn the root. The error for a file that doesn’t match the input’s accept. Without it, a Spanish default message.

From the CDN, without a build, load taisho.file-upload.css along with taisho.base.css. Also load:

  • taisho.button.css
  • taisho.icon.css
  • taisho.spinner.css

For how Core works in general, see Behavior.

Accessibility

  • The picker opens from the button in the zone (a real <button>: Tab reaches it, and Enter or Space activates it). Drag and drop is a pointer enhancement: the zone isn’t a tab stop.
  • It’s built on a real <input type="file"> to open the native picker.
  • Files that fail validation show the reason next to their name.
  • Each file in the list has a button with the aria-label “Remove <name>”. With multiple, the list accumulates selections, and an empty list takes no space and isn’t exposed (hidden).

Keyboard

On top of what the browser already does (Tab moves focus, Enter activates a button).

Key What it does
Enter/SpaceOn the “Select files” button, opens the file picker.

Verification

What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.

  • axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
  • keyboard Key map documented above, checked against the component.
  • screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.