Skip to content
Haze UI

File upload

Dashed drop area over a real file input; a small script lists the chosen files with a remove button and announces changes.

pnpm dlx shadcn@latest add @haze/file-upload
Open preview in a new tab
Livesmall script

When to use

  • Attaching invoices, screenshots or documents to a form
  • Uploads where dragging files onto the page area should work as well as clicking

When not to use

  • Uploads that need previews, progress bars or resumable transfers, which need an application-level uploader
  • A single small avatar change; a button that opens the file picker is lighter

Installation

Add the Haze registry to components.json once, then install File upload with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/file-upload
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–File input id; the visible title is a label for it, the hint id is <id>-hint.
namestringidForm field name.
label*string–Title inside the box and the accessible name of the input.
hintstring–Help text such as accepted types and the size limit; linked with aria-describedby.
acceptstring–Comma-separated file types, as in the native accept attribute.
multipleboolean–Allows choosing more than one file.
classstring–Extra classes on the wrapper.
...restattributes–Any other input attribute, for example required or disabled. A passed aria-describedby is joined to the hint id, not a replacement for it.

Keyboard interactions

Tab
Focuses the file input
Enter or Space
Opens the file dialog

Accessibility

  • The invisible file input fills the whole box, so click, drag-and-drop and the operating system's file dialog are all native; the visible title is its label.
  • With the script, chosen files are listed as rows, and a polite live region announces what was added or removed and how many files are selected. Without scripting the native file input is shown below the hint, so the browser itself displays the chosen file names.
  • Each row has a remove button named "Remove <file name>". Removing a file returns focus to the file input.
  • The focus outline is drawn on the box with has-focus-visible, because the input itself has no visible edge. While files are dragged over the box its border and tint change; this is a hint only, and dropping works the same either way.
  • Type and size limits are written in the hint; accept only filters the picker, so validate files on the server.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "File upload" with `npx shadcn@latest add @haze/file-upload`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import FileUpload from "@/components/haze/ui/file-upload.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/file-upload.md

  • Customize with real content

    Adapt the Haze file-upload ui for our product. Replace the demo values of these props with our real content: id, name, label, hint, accept, multiple, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The invisible file input fills the whole box, so click, drag-and-drop and the operating system's file dialog are all native; the visible title is its label. With the script, chosen files are listed as rows, and a polite live region announces what was added or removed and how many files are selected. Without scripting the native file input is shown below the hint, so the browser itself displays the chosen file names. Each row has a remove button named "Remove <file name>". Removing a file returns focus to the file input. The focus outline is drawn on the box with has-focus-visible, because the input itself has no visible edge. While files are dragged over the box its border and tint change; this is a hint only, and dropping works the same either way. Type and size limits are written in the hint; accept only filters the picker, so validate files on the server. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using file-upload, check it fits: use it when attaching invoices, screenshots or documents to a form; uploads where dragging files onto the page area should work as well as clicking. Avoid it when uploads that need previews, progress bars or resumable transfers, which need an application-level uploader; a single small avatar change; a button that opens the file picker is lighter. Alternatives: @haze/input, @haze/button, @haze/field.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog