shadcn.io is not affiliated with official shadcn/ui
Restricted Types File Upload Block for React
A format allow-list (PDF, PNG, JPG, DOCX, CSV, ZIP) that builds the drop zone's accept, checking each file by extension and by reported type, with an Accepted and a Refused list and the reason for each refusal.
Installation
Overview
Show people exactly why a file was turned away, with this file upload panel for React with Base UI. It is the title-file intake of Deedhaven, a deed and title portal. At the start, six Checkbox cells on shared hairlines list the formats you can allow, and the ticked ones build the accept of the File Upload drop zone at the end. Every file gets two verdicts, by its extension and by the type the browser reports for it, each ticked or crossed, and a mismatch is explained ("invoice.pdf is reported as image/png: renamed?"). Files that pass sit under Accepted and the rest under Refused. The lists come from the ticks, so unticking PDF moves every PDF to Refused at once. Four files are typed to start, one of them renamed. The panel's bands are ruled by Guides. It is built from File Upload, Checkbox, Button and Guides, with a CSS entrance only. For intake portals, document uploads and any form that must say what it takes.
FAQ
What are the two verdicts?
The extension verdict looks at the name: is the file's extension on the ticked list. The type verdict looks at file.type, the type the browser reports, which it gives without opening the file. A file passes when its extension is allowed and its type is not contradicting the list (a file with no reported type passes on the extension). The reason for a refusal is written out under the file.
Is the reported type proof of what is inside?
No, and the zone's hint says so. Browsers usually work the type out from the extension or the operating system's table, never from the file's bytes, so a renamed file often reports a matching type. The seeded renamed file is typed to show what a mismatch looks like. This block never opens a file; check contents on your server before you trust one.
Is accept real?
Yes. The ticked formats become the zone's accept string (extensions and types), so the picker filters and the zone refuses files that match neither. Refused files are still listed, with the reason, from the zone's reject handler. Change FORMATS to offer other types.
Can I untick everything?
No. The last allowed format cannot be unticked: the status line says "Keep at least one type on the list." Each box is named for its format and the whole cell is its hit area.
What stays local?
All of it. Nothing is uploaded or saved; the lists live in the block's state and a reload restores the four typed files. Each row has a Remove button that names its file, and a polite status line reports every change. To wire it, send the accepted files to your server and re-check type and contents there.
Related
- Pro
A per-file size cap set with a slider (5 to 100 MB) and a total meter with an 80% tick; files over the cap or past the total are listed with the reason and not counted.
- Pro
A project folder's drop zone that folds into a slim Add more strip over its file list as files arrive, with a running total against 25 MB, Remove on each row and Clear all.
- Pro
A drawn project brief that is itself the drop zone: nothing shows until a file is dragged over it, then a full-bleed message appears, and dropped files join an attachments list with a short bar.
- Pro
Upload Queue Preview Gallery
Select and actA file drop zone that lists every file you pick or drop (name and size, never opened) beside a queue of four seeded files in their states, with Retry, Remove and a Send button.
- Pro
A deep inset drop zone whose 1 px edge lights up where the pointer is and glows evenly on focus, over a tray of attachment rows with Remove and Clear tray.
- Pro
An illustrated empty state whose drawn folder is the drop zone: a pick closes the folder and lists the file, with working Add files, Paste a link and New folder shortcuts.