File upload table
A drop zone and a table of the files being sent, with per-row progress, removal and extra columns for classification.
Choose files or drop them on the area. The sample only keeps them in memory.
When to use
- To upload several documents at once and classify each one, as in the dialog that adds subsidies to a case.
- When every row needs extra information next to the file (a type, a role) through
renderExtras. - When the list can grow long and should scroll inside a dialog.
When not to use
- One file. Use Single file uploader.
- A few documents shown as cards with actions. Use File upload cards.
- A list of files already stored. Use Table, since this component is about files that are about to be sent.
Anatomy
| Part | Role |
|---|---|
| Drop zone | A dashed area that is also a button. After the first file it shrinks to one line. |
| Title | Optional heading with the file count: “Documentos (3)”. |
| Batch actions | Optional tableBatchActions at the right of the title. |
| Table | File (icon, name, size), an optional extra column and the remove action. |
The hook that owns the files, the drag state and the transfer is not part of the component. The host passes the list and the handlers.
States
Empty
With files
The icon follows the file extension. A name longer than 30 characters is truncated and shown in a tooltip. A row whose progress is 100 with an empty path, when no batch is pending, gets the error badge.
Documentos (3)
| Arquivo | Ações |
|---|---|
peticao-inicial.pdf 2.29 MB | |
procuracao-assinada-pelo-cliente-final-versao-2.pdf 820.31 KB | |
comprovante-de-residencia.pdf 302.73 KB Erro |
Uploading
With isPending, a row shows a progress bar while progress is below 100 and it is isUploading or has some progress.
Documentos (2)
| Arquivo | Ações |
|---|---|
peticao-inicial.pdf 2.29 MB | |
procuracao-assinada.pdf 820.31 KB |
Extra column
renderExtras adds a column; extrasHeader names it. Use it for a select that classifies the document.
Documentos (2)
| Arquivo | Tipo do documento | Ações |
|---|---|---|
peticao-inicial.pdf 2.29 MB | Petição inicial | |
procuracao-assinada-pelo-cliente-final-versao-2.pdf 820.31 KB | Procuração |
Dragging and disabled
Content
- Pass every string through
labels: “Arraste ou selecione os arquivos”, “Adicionar mais arquivos”, “Documento”, “Ações”, “Erro”. removeFileAriaLabelreceives the file name and returns “Remover arquivo peticao-inicial.pdf”.- Pass
extrasHeadertoo; it has no key inlabels. - The
titlenames the group in the user’s terms: “Documentos do processo”.
Accessibility
- The drop zone is a
buttonwitharia-label={labels.dropZoneAriaLabel}.EnterandSpaceopen the file picker; a disabled zone is removed from interaction. The input behind it is hidden and out of the tab order. - Dropping files is not required: the picker does the same job from the keyboard.
- The table is a native
tablewith header cells, so row and column relations are read by assistive technology. - Each remove button is named with the file name. Its icon is
aria-hidden; the button is 32px, above the 24px minimum. - A long name is truncated visually; the full name stays in the DOM, and a tooltip shows it on hover.
- The error badge has text (“Erro”), so the status is not only a color.
Code
import { FileUploadTable } from "@repo/ui/file-upload-table";
<FileUploadTable
fileType={["file", "tabular"]}
files={upload.files}
isDragging={upload.isDragging}
isPending={upload.isPending}
labels={labels}
onChangeFile={upload.onChangeFile}
onDragLeave={upload.onDragLeave}
onDragOver={upload.onDragOver}
onDrop={upload.onDrop}
removeFile={upload.removeFile}
scrollable
title={t("documents")}
/>;
Props
FileUploadTable| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Extra classes for the root. Layout only |
disabled | boolean | — | Disables the drop zone button |
extrasHeader | string | — | Header of the extra column. Falls back to the Portuguese text “Opções” |
files | FileRow[] | — | Rows to list. Each has `file`, `name`, `path`, `progress` and `isUploading` |
fileType | string | string[] | — | Kind of file accepted: `file` or `pdf` (PDF), `image`, `audio`, `video`, `compressed`, `tabular` or `all`, or a list of them. Sets the input `accept` |
isDragging | boolean | — | Highlights the drop zone while a file is dragged over it |
isPending | boolean | — | A batch is uploading. Shows progress bars and hides the error badge |
labels | Partial<FileUploadTableLabels> | — | Copy of the table. Any key left out falls back to Portuguese text |
onChangeFile | (event: ChangeEvent<HTMLInputElement>) => void | — | Change handler of the hidden file input |
onDragLeave | () => void | — | Called when a drag leaves the drop zone |
onDragOver | DragEventHandler<HTMLElement> | — | Called while a drag is over the drop zone. Call `preventDefault` |
onDrop | DragEventHandler<HTMLElement> | — | Called when files are dropped. Call `preventDefault` |
removeFile | (name: string) => void | — | Called with the file name when the user removes a row |
renderExtras | (file: FileRow) => ReactNode | — | Content of an extra column, per row |
scrollable | boolean | — | Limits the table height (50vh) and scrolls it |
scrollAreaClassName | string | — | Replaces the default max height of the scroll area |
tableBatchActions | ReactNode | — | Actions next to the title, such as “Remove all” |
title | string | — | Heading above the table. The file count is added after it |
FileRow (items of files)| Prop | Type | Default | Description |
|---|---|---|---|
file | File | — | The browser file. Its size is shown on the row. |
name | string | — | File name. Also the row key and the argument of `removeFile`. |
path | string | — | Where the file was stored. An empty string with progress 100 means the upload failed. |
progress | number | — | Percentage from 0 to 100. |
isUploading | boolean | — | With `isPending`, shows the progress bar even at 0%. |
FileUploadTableLabels| Prop | Type | Default | Description |
|---|---|---|---|
addMoreFiles | string | — | Text of the drop zone when there are files. |
columnActions | string | — | Header of the actions column. |
columnFile | string | — | Header of the file column. |
dragOrSelectFiles | string | — | Text of the drop zone when empty. |
dropZoneAriaLabel | string | — | Accessible name of the drop zone button. |
errorBadge | string | — | Text of the error badge. |
removeFileAriaLabel | (fileName: string) => string | — | Accessible name of each remove button. |
Known issues
| Issue | Effect |
|---|---|
labels falls back to Portuguese text, and extrasHeader falls back to “Opções”. |
The package has copy of its own. An English app that omits a key shows Portuguese. |
File names and sizes are raw p elements with text-sm and text-xs, not Typography. |
They do not follow the type scale. |
Rows are keyed by name, and removeFile receives only the name. |
Two files with the same name share a key (React warns) and a remove can drop the wrong row. |
onChangeFile, onDragOver and onDrop are required and the component does nothing with the files itself. |
Every use needs a hook (the app has useMultiFileUpload). There is no default behavior, so it cannot be used alone. |
The tooltip for a long name wraps a p that is not focusable. |
Keyboard users never see the tooltip; they get the truncated text only. |
The remove button is h-8 w-8 (32px) and has no confirmation. |
It is easy to remove a file by accident on a touch device. |
isDragging only changes the border width to border-2. |
The drag feedback is subtle on a large table. |