Skip to content
All components
Forms

File upload

Let people add files by keyboard, pointer or drag and drop, validate them against type and size, and show each file's progress and errors.

A keyboard-ready dropzone with validation, and a file list with progress.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add file-upload

Then import it from @/components/ui/file-upload. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Dropzone with list

Validate added files and list them with progress and actions. Rejected files get a message; accepted files reach onFiles and the consumer owns the list. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { FileUploadDropzone, FileUploadItem, FileUploadList } from "@/components/ui/file-upload"

type Entry = { id: string; name: string; size: number; progress: number; status: "uploading" | "complete" | "error"; error?: string }

const initialFiles: Entry[] = [
  { id: "file-upload-demo-1", name: "brand-guidelines.pdf", size: 2_400_000, progress: 100, status: "complete" },
  { id: "file-upload-demo-2", name: "homepage-hero.png", size: 860_000, progress: 45, status: "uploading" },
  { id: "file-upload-demo-3", name: "quarterly-report.pdf", size: 4_100_000, progress: 20, status: "error", error: "Upload failed. Check your connection and try again." },
]

export function FileUploadDropzoneWithList() {
  const [files, setFiles] = React.useState(initialFiles)

  // No network here: added files appear as complete so the list stays honest.
  const add = (incoming: File[]) =>
    setFiles((current) => [
      ...current,
      ...incoming.map((file, index) => ({ id: `${file.name}-${Date.now()}-${index}`, name: file.name, size: file.size, progress: 100, status: "complete" as const })),
    ])
  const remove = (id: string) => setFiles((current) => current.filter((file) => file.id !== id))
  const retry = (id: string) =>
    setFiles((current) => current.map((file) => (file.id === id ? { ...file, status: "complete", progress: 100, error: undefined } : file)))

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <div className="flex flex-col gap-3">
        <FileUploadDropzone accept=".pdf,image/png,image/jpeg" maxSize={5 * 1024 * 1024} multiple onFiles={add} hint="PDF, PNG or JPG, up to 5 MB" />
        {files.length ? (
          <FileUploadList aria-label="Uploaded files">
            {files.map((file) => (
              <FileUploadItem
                key={file.id}
                name={file.name}
                size={file.size}
                progress={file.progress}
                status={file.status}
                error={file.error}
                onRemove={() => remove(file.id)}
                onRetry={() => retry(file.id)}
              />
            ))}
          </FileUploadList>
        ) : null}
      </div>
    </div>
  )
}

Single image

Accept one image with a size limit and a custom action label. The hint describes the picker button. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { FileUploadDropzone } from "@/components/ui/file-upload"

export function FileUploadSingleImage() {
  

  
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <FileUploadDropzone accept="image/*" maxSize={1024 * 1024} onFiles={() => {}} actionLabel="Upload a photo" hint="One image, up to 1 MB" />
    </div>
  )
}

Disabled

Show a dropzone that cannot accept files and say why. The button is disabled and drops are ignored. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { FileUploadDropzone } from "@/components/ui/file-upload"

export function FileUploadDisabled() {
  

  
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <FileUploadDropzone disabled onFiles={() => {}} hint="Uploads are paused while the workspace is read-only" />
    </div>
  )
}

Item states

Compare uploading, complete and failed file items. Progress is named by the file; errors are text; every action names its file. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { FileUploadItem, FileUploadList } from "@/components/ui/file-upload"

export function FileUploadItemStates() {
  

  
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <FileUploadList aria-label="File states">
        <FileUploadItem name="interview-recording.mp4" size={48_000_000} progress={68} status="uploading" onRemove={() => {}} removeLabel="Cancel" />
        <FileUploadItem name="contract-signed.pdf" size={320_000} status="complete" onRemove={() => {}} />
        <FileUploadItem name="a-very-long-file-name-from-the-shared-drive-final-v3-approved.xlsx" size={92_000} status="error" error="This file is larger than the 50 KB limit." onRemove={() => {}} />
      </FileUploadList>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

FileUploadDropzone

A drop area with a real button that opens the file picker. Files arrive through onFiles after accept/maxSize validation; nothing is uploaded here.

FileUploadDropzone props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
acceptstring | undefined—Accepted types, in the native accept format: ".pdf,image/*". Also enforced for dropped files.
maxSizenumber | undefined—Largest accepted file in bytes. Larger files are rejected with a message.
multipleboolean | undefinedfalseAllow several files at once. When false, only the first file is kept.
disabledboolean | undefinedfalseDisable the picker button and ignore drops.
getRejectionMessage((rejection: Omit<FileRejection, "message">) => string) | undefined—Write your own rejection messages, for example to localize them.
actionLabelstring | undefined"Click to upload"Visible text of the picker button. It is also the button's accessible name.
dragLabelstring | undefined"or drag and drop"Text after the button that mentions drag and drop. Keep the button usable on its own; dragging is optional.
hintReact.ReactNode—Constraints shown under the action, such as "PNG or PDF, up to 5 MB". Associated with the button as its description.
iconReact.ReactNode—Replace the decorative upload icon.
Inherited props (13)
FileUploadDropzone inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FileUploadItem

One file in the list, with its size, progress, error and actions. The state is presentational: the consumer uploads, updates progress and removes files.

FileUploadItem props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
name(required)string—File name, shown in full to assistive technology even when truncated visually.
sizenumber | undefined—File size in bytes; formatted for display.
progressnumber | undefined—Upload progress from 0 to 100 while status is uploading.
status"error" | "uploading" | "complete" | undefined"complete"uploading shows a progress bar, complete a check, error the message in error.
errorstring | undefined—What went wrong and what to do next, shown when status is error.
removeLabelstring | undefined"Remove"Verb announced before the file name on the remove button.
retryLabelstring | undefined"Retry"Verb announced before the file name on the retry button.
iconReact.ReactNode—Replace the decorative file icon.
Inherited props (14)
FileUploadItem inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
refReact.Ref<HTMLLIElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLLIElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLLIElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLLIElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLLIElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLLIElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLLIElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.

FileUploadList

A list of files being uploaded or already added.

FileUploadList props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
FileUploadList inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLUListElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLUListElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLUListElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLUListElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLUListElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLUListElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLUListElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/file-upload.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Forms that need one or more documents or images.
  • Settings pages for avatars, logos or imports.
  • Any upload where people should see progress and recover from errors.

When not to use

  • Files attached to a chat message; use attachment.
  • Choosing from files already on the server; use a list or a combobox.
  • A single tiny file in a dense form, where a plain native file input is enough.

Anatomy

FileUploadDropzone
Drop area with a native picker button, hint, rejection status region and hidden file input. Props: accept, maxSize, multiple, disabled, onFiles, onReject, getRejectionMessage, actionLabel, dragLabel, hint, icon.
FileUploadList
Native list of items; name it with aria-label or aria-labelledby.
FileUploadItem
One file with name, size, status (uploading, complete, error), progress, error, onRemove and onRetry.
formatFileSize
Helper that formats bytes for display.

Keyboard & interaction

  • Tab reaches the picker button; Enter or Space opens the native file dialog.
  • Dropping files over the area highlights it; dropped files go through the same validation as picked ones.
  • Rejected files produce messages in a status region and reach onReject; accepted files reach onFiles.
  • Remove and retry are native buttons named with their verb and the file name.
  • Progress bars are named by the file name and report the percentage.

Responsive behavior

  • The dropzone and list fill their container and reflow at 320px.
  • Long file names truncate visually and stay available in full through title and the accessible name.
  • Item actions keep at least 32x32 targets.

Content guidelines

  • State accepted types and the size limit in hint before people choose a file.
  • Rejection messages name the file and the rule it broke.
  • Error text says what to do next: 'Check your connection and try again.'

Alternatives

  • Attachment — Files shown inside a conversation.
  • Progress — Progress for work that is not a file upload.
  • Input — A plain native file input in a compact form.

Resources