Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input examples · Special

File Upload with List Input for React

A multiple file input that lists the chosen files with their sizes and a remove button.

Framework
UI library

File inputs show little about what was picked. This example uses a type file input with multiple and lists every chosen file under it, with a file icon, its name, its size in kilobytes and a button to remove it. Use it for attachments, document uploads and anywhere people pick several files before submitting.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does the field accept several files?

multiple on the file input lets the picker select more than one. Each time the selection changes, the chosen files are copied from the input into a list kept in state, which renders the rows.

What does each row show?

A FileTextIcon, the file name, truncated when it's long, and the size in kilobytes with one decimal, from the file's size divided by 1024. The rows are a list with a border and rounded corners.

How does the remove button work?

It's a ghost Button at size icon-xs with an XIcon. It carries its row's index in data-index and removes that file from the list. Its aria-label names the file, such as Remove report.pdf.

Does removing a row change what the input holds?

No. The list is the example's own state; the browser's file input still holds the files from the last pick. Submit the list from state, for example with FormData, rather than the input itself.

How do I limit the file types?

Add accept to the input, such as accept="image/*" or accept=".pdf,.docx". The picker then filters to those types; check them again on the server.

How is Upload Files tied to the field?

Clicking the label focuses the field, and screen readers announce it with the field. FieldLabel sets htmlFor to file-upload, the input's id.