Skip to content

feat(file-upload): add a file picker and dropzone - #934

Closed
urstruelysv wants to merge 7 commits into
cosscom:mainfrom
urstruelysv:codex/file-upload-923
Closed

urstruelysv wants to merge 7 commits into
cosscom:mainfrom
urstruelysv:codex/file-upload-923

Conversation

@urstruelysv

@urstruelysv urstruelysv commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #923.

Summary

Apps can use the same coss field for browsing or dropping files, showing rejections, and submitting accepted attachments through a native form.

  • Adds FileUpload, FileUploadDropzone, FileUploadTrigger, FileUploadList, and FileUploadItem. The trigger is a keyboard-accessible button. The list shows file names and sizes, image previews, removal, and optional progress supplied by the app.
  • Validates type, size, and count for both picking and dropping. Valid files fill the available slots in order. An invalid replacement preserves the previous file, and a rejection blocks submission until resolved.
  • Supports controlled and uncontrolled File[] values, native FormData, and form reset. The picker is separate from the form input so reopening or canceling it preserves the committed files. Use Field validationMode="onChange" for immediate rejection messages.
  • Includes docs, the avatar, progress, and native form particles, and the generated registry entries. The app handles upload transport.

Try it

Open the Native forms example in the File Upload docs. Drop four small PDFs. Three should appear and the extra file should produce an error that blocks submission. Remove one accepted file and submit. The output should name only the remaining files. Reset should clear the list and output.

Verification

  • bun run test passed all 93 tests, including 37 File Upload tests. The regressions cover late-mounted form reset and both rapid replacement and recovery when application and file rejections overlap.
  • Chromium 158 confirmed that a rapid replacement stays blocked while an existing application error awaits revalidation. An accepted replacement submits once with only that file, including when the earlier application error has already cleared. The reset checks kept the list and submitted files empty after a rerender. Canceled and unrelated resets preserved the selection.
  • Workspace typecheck, lint, formatting, and registry dependency validation passed. All five generated registry entries matched their source, and the component installed from the generated registry and type-checked in a disposable app. The apps/ui production build passed with Webpack.

With overlapping debounced errors, the old rejection can briefly remain visible after the application accepts a replacement, until Field refreshes. The Chromium checks used scripted file selection. Firefox, WebKit, the OS picker, and screen readers still need manual verification. The full monorepo Turbopack build was not verified locally.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@urstruelysv is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@urstruelysv

Copy link
Copy Markdown
Author

Hi, thanks for opening #923. I built this to close it.

Why it’s built this way

Base UI has no file upload primitive, so the selection logic lives in a useFileUpload hook and the parts follow the usual coss conventions (data-slot, cn, and forwarded props). I used Origin’s use-file-upload as a reference for behaviour. The coss version needs to work with controlled state, native forms, and Field.

Three behaviours I chose. Please push back if any is wrong.

  1. If someone selects more files than maxFiles allows, the valid files that fit are accepted and each extra file gets its own rejection reason. Rejecting the whole batch felt worse to use. In single-file mode, a valid replacement takes the place of the old file, and an invalid replacement keeps the old file.
  2. A rejection blocks submission until a successful selection, removal, or reset clears it. I use setCustomValidity on the named file input so the browser can block submission without a custom submit handler.
  3. Base UI’s Field validates on submit by default. The docs and particles use validationMode="onChange" to show rejections as they happen. The usage snippet in the issue needs that prop for immediate feedback. The integration uses public APIs.

Dropzone click. Right now, only the trigger button opens the picker. Would you prefer the whole dropzone to open it too?

Where I’d like your eyes

The hook is the part I’d most like feedback on. It keeps the native file input, the Field error, and the accepted list in sync, and that’s where I’d expect edge cases.

Verification

  • 37 File Upload DOM tests covering selection, drop, reset, controlled parents that decline an update, Field errors, and focus after removal.
  • Biome, typecheck, and registry:validate-deps.
  • registry:build, with the generated files committed.

Firefox, Safari, and screen-reader behaviour remain untested.

I used AI tools (Codex and Claude) to help write and review this. I’m happy to walk through any part of the code or the checks.

I’ll respond to review comments the same day. If it’s easier to split the hook and the component into two PRs, I can do that.

@urstruelysv

urstruelysv commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

Safari keyboard demo · 90 seconds, silent

file-upload-safari-silent.mp4

Skip to 0:25 for the fourth-file rejection, 0:55 for focus after removal, 1:10 for the submitted filenames, or 1:20 for Reset.

I tested the Supporting documents example on localhost at 6fdff127 with Safari 26.5.2 on macOS 26.5.2.

  • Picker and validation. Using only the keyboard, I focused the trigger and pressed Space. Safari opened its native picker. I selected four PDFs. The first three stayed in the list and the form showed “04-extra.pdf” exceeds the 3 file limit. Pressing Submit returned focus to the trigger and produced no submission result.
  • Recovery and focus. I removed 01-brief.pdf with Space. The rejection cleared and keyboard focus moved to Remove 02-notes.pdf.
  • Submit and Reset. The example read 02-notes.pdf and 03-plan.pdf from native form data. Reset cleared both the list and the displayed submission result. The empty required field showed “Select a file.”
  • VoiceOver. With VoiceOver enabled, its caption panel identified the picker dialog. Safari exposed the rejection text in its accessibility tree, but the VoiceOver captions I captured contained only dialog and button feedback. I could not confirm that VoiceOver announced the filename and reason when the picker closed. That part still needs a listening check.
  • Automated check. bun test ./packages/ui/test/components/file-upload.dom.tsx passed all 37 tests (131 assertions). React printed two act(...) warnings.

@pasqualevitiello

Copy link
Copy Markdown
Contributor

Thanks a lot for this, @urstruelysv. File upload is out of scope for coss ui right now, so we're closing it for now. It's about scope, not the quality of your work.

@urstruelysv

Copy link
Copy Markdown
Author

Thanks for the clear answer, understood on scope. One thing I noticed while reading the repo: about 14 components animate with no prefers-reduced-motion handling (accordion, collapsible, popover, tooltip, sheet, drawer, sidebar and others), while dialog, tabs and toast have it since #864. Would you take a small PR for that, say 4 or 5 components at a time? If you'd rather not, no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a File Upload component with drag-and-drop

2 participants