# File upload

Choose or drop files, inspect limits and remove selections.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs choose or drop files, inspect limits and remove selections.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than file upload.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install File upload

```sh
npx shadcn@latest add @tidal-pro/file-upload
```

Stylesheets: `components/ui/tidal.css`, `components/ui/file-upload.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/file-upload.css";
import{TidalFileUpload}from"./components/ui/file-upload";
export default()=><div className="tidal-scope"><TidalFileUpload files={[new File([], "example.txt")]} label={"Demo"} onFilesChange={() => {}}/></div>;
```

## Structured props

- `TidalFileUpload.files: ReadonlyArray<File>`: Required files value accepted by this exported component.
- `TidalFileUpload.label: string`: Required label value accepted by this exported component.
- `TidalFileUpload.onFilesChange: (files: File[]) => void`: Callback invoked when the files change interaction is proposed.
- `TidalFileUpload.accept?: string | undefined` (default ""): Optional accept value accepted by this exported component.
- `TidalFileUpload.description?: string | undefined`: Optional description value accepted by this exported component.
- `TidalFileUpload.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalFileUpload.error?: string | undefined` (default ""): Optional error value accepted by this exported component.
- `TidalFileUpload.fileStates?: ReadonlyMap<File, TidalFileStatus> | undefined`: Optional file states value accepted by this exported component.
- `TidalFileUpload.inputRef?: Ref<HTMLInputElement> | undefined`: Optional input ref value accepted by this exported component.
- `TidalFileUpload.maxFiles?: number | undefined` (default 5): Optional max files value accepted by this exported component.
- `TidalFileUpload.maxSize?: number | undefined` (default 10_000_000): Optional max size value accepted by this exported component.
- `TidalFileUpload.onReject?: ((rejections: TidalFileRejection[]) => void) | undefined`: Callback invoked when the reject interaction is proposed.

## Complete usage example

[Source](https://tidalui.com/examples/file-upload.tsx) | [Manifest](https://tidalui.com/examples/file-upload.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useEffect, useRef, useState } from "react";

import { Plus, RotateCcw, Check, X } from "lucide-react";

import { TidalFileUpload, type TidalFileStatus } from "./components/ui/file-upload";

import "./components/ui/file-upload.css";



const tidalExampleStyles = ".tidal-scope .file-upload-specimen{width:100%;max-width:580px;padding:28px;border:1px solid var(--t-border);border-radius:var(--t-radius-card);background:var(--t-subtle);color:var(--t-ink);box-shadow:0 22px 44px -32px #00000038}.tidal-scope .file-upload-demo-tools{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:18px}.tidal-scope .file-upload-demo-tools>button,.tidal-scope .file-upload-demo-prepare{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-width:44px;min-height:44px;padding:9px 12px;border:1px solid var(--t-border);border-radius:var(--t-radius-control);background:var(--t-surface);color:var(--t-ink);font:inherit;font-size:11px;cursor:pointer;transition:background 140ms,transform 140ms var(--t-ease-out)}.tidal-scope .file-upload-demo-tools>button:hover{background:var(--t-wash)}.tidal-scope .file-upload-demo-tools>button:active,.tidal-scope .file-upload-demo-prepare:active:not(:disabled){transform:scale(.98)}.tidal-scope .file-upload-demo-prepare{width:100%;margin-top:10px;background:var(--t-ink);color:var(--t-surface);border-color:var(--t-ink)}.tidal-scope .file-upload-demo-prepare:focus-visible{outline:3px solid currentColor;outline-offset:-5px}.tidal-scope .file-upload-demo-prepare:disabled{opacity:.5;cursor:not-allowed}.tidal-scope .file-upload-demo-note{font-size:11px;line-height:1.6;color:var(--t-muted);margin:15px 0 0}\n@media(max-width:480px){.tidal-scope .file-upload-specimen{padding:18px}}@media(prefers-reduced-motion:reduce){.tidal-scope .file-upload-demo-tools>button:active,.tidal-scope .file-upload-demo-prepare:active:not(:disabled){transform:none}}";

export function FileUploadDemo(){
  const [files,setFiles]=useState<File[]>([]),[states,setStates]=useState<Map<File,TidalFileStatus>>(new Map()),[running,setRunning]=useState(false),[revision,setRevision]=useState(0);
  const timer=useRef<ReturnType<typeof setTimeout>|undefined>(undefined),progress=useRef(0);
  useEffect(()=>()=>clearTimeout(timer.current),[]);
  function cancel(){clearTimeout(timer.current);setRunning(false);setStates(current=>new Map([...current].filter(([,state])=>state.state!=="uploading")));}
  function change(next:File[]){cancel();setFiles(next);setStates(current=>new Map([...current].filter(([file])=>next.includes(file))));}
  function samples(){cancel();setStates(new Map());setFiles([new File(["Project overview\n".repeat(64)],"Project brief.txt",{type:"text/plain"}),new File(["# Launch checklist\n".repeat(48)],"Launch checklist.md",{type:"text/markdown"})]);}
  function reset(){cancel();setFiles([]);setStates(new Map());setRevision(n=>n+1);}
  function prepare(){if(running||!files.length)return;progress.current=0;setRunning(true);setStates(new Map(files.map(f=>[f,{state:"uploading",progress:0,label:"Preparing sample"}])));const step=()=>{progress.current=Math.min(100,progress.current+20);setStates(new Map(files.map(f=>[f,{state:progress.current===100?"complete":"uploading",progress:progress.current,label:progress.current===100?"Sample ready":"Preparing sample"}])));if(progress.current<100)timer.current=setTimeout(step,160);else setRunning(false);};timer.current=setTimeout(step,160);}
  return <div className="file-upload-specimen"><TidalFileUpload key={revision} label="Attachments" files={files} onFilesChange={change} accept=".txt,.md,.pdf" maxFiles={3} maxSize={2_000_000} fileStates={states}/><div className="file-upload-demo-tools"><button type="button" onClick={samples}><Plus size={14} aria-hidden="true"/>Add samples</button><button type="button" onClick={reset}><RotateCcw size={14} aria-hidden="true"/>Reset</button></div><button type="button" className="file-upload-demo-prepare" disabled={!files.length} aria-busy={running} onClick={running?cancel:prepare}>{running?<><X size={15} aria-hidden="true"/>Cancel sample</>:<><Check size={15} aria-hidden="true"/>Prepare sample</>}</button><p className="file-upload-demo-note">Local files and preparation. Nothing is uploaded.</p></div>;
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <FileUploadDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Controlled files (readonly File[]) and onFilesChange required; visible label required. Optional description/error/disabled, accept(extension or MIME list), maxFiles(default5) and maxSize(default10million decimalbytes). Finite counts floor to at least1; invalid bounds/accept syntax show a configuration error and disable choosing. Zero maxSize permits empty files. Native picker and file-only drag/drop share ordered validation; multiple selections append to current files, maxFiles1 replaces the selection with the first valid incoming file. Invalid incoming files are rejected without discarding an existing single file; different File objects are never deduplicated by filename. onReject receives file/code/message records; validateFileSelection and formatFileSize are exported for integration. Metadata/type checks are local UX validation; consumers own actual uploads and final validation. Root forwards native div/ref/attributes/drag callbacks; preventing the caller onDrop stops automatic selection. inputRef exposes the unnamed native picker, including React19 callback-ref cleanup. Native picker resets after selection for same-file reselection; controlled files remain the source of truth. Native FormData does not include this unnamed/reset picker: append your controlled File objects and implement any required-field validation in the consumer. No file body is read, uploaded or persisted by the component. Native choose/remove controls44px; removal focuses Choose before proposing the next array, and consumers own aborting any active request. Optional fileStates ReadonlyMap<File,{state:uploading|complete|error,progress?,label?}> drives real consumer-owned progress/status. Finite percentages clamp0..100; unknown progress omits aria-valuenow, complete resolves100. Override labels for local simulations. A single polite status describes actual selected files and state counts, never each percentage; linked validation feedback and full filenames remain readable. Native disabled controls, internally scrollable file lists, long-name wrapping, scoped light/dark CSS and reduced motion supported. No automatic upload, network request, storage or timer is introduced. Decorated folder entry and drag pose, row entrance and controlled rails reflect real interaction.
