File Input

FileInput is a styled file picker built on a visually hidden native file input inside a label, so the whole surface opens the system file dialog. It shows a leading icon, the placeholder or selected file name (or a count for multiple files), and an optional clear button, following the same variant, size, and tone contract as Input.

File Input
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://ai2.design/r/tokens.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @ai2/file-input

Requires @ai2 in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { FileInput } from "@/components/ui/file-input"export function Example() {  return <FileInput name="attachment" accept="application/pdf" />}
  • Replacing a bare input[type=file] in forms where the field must match the visual style of text inputs and selects
  • Letting users attach one or several files, with a visible file name or file count after selection
  • Showing validation or success states on an upload field through tone and aria-invalid
  • Offering a quick way to clear a chosen file without reopening the dialog

Examples

Basic single file

Default outline variant at medium size with the paperclip icon and the clear button shown after selection.

basic-single-file.tsx
import { FileInput } from "@/components/ui/file-input"export function BasicFileInput() {  return <FileInput name="resume" accept=".pdf,.docx" />}

Multiple images with custom placeholder

Accepts several images. After selection the field displays a count such as "3 files".

multiple-images-with-custom-placeholder.tsx
import { FileInput } from "@/components/ui/file-input"export function GalleryUpload() {  return (    <FileInput      name="photos"      accept="image/*"      multiple      placeholder="Add photos"      variant="soft"    />  )}

Invalid state with danger tone

Marks the field as invalid with aria-invalid and the danger tone for form validation feedback.

invalid-state-with-danger-tone.tsx
import { FileInput } from "@/components/ui/file-input"export function RequiredAttachment({ error }: { error?: string }) {  return (    <div className="grid gap-1.5">      <FileInput        name="contract"        required        size="lg"        tone="danger"        aria-invalid={Boolean(error)}      />      {error ? <p className="text-sm text-danger">{error}</p> : null}    </div>  )}

Custom icon without clear button

Swaps the paperclip for a custom icon element and hides the clear button with clearable={false}.

custom-icon-without-clear-button.tsx
import { FileInput } from "@/components/ui/file-input"import { Upload } from "lucide-react"export function UploadOnly() {  return (    <FileInput      name="import"      accept=".csv"      icon={<Upload />}      placeholder="Upload CSV"      clearable={false}      ghost    />  )}

API reference

PropTypeDefaultDescription
variant"outline" | "soft" | "ghost" | null | undefined"outline"Visual style of the field surface, from VariantProps of fileInputVariants.
size"sm" | "md" | "lg" | null | undefined"md"Height, gap, padding, radius, and text size. sm uses min-height 32px, md 36px, lg 40px.
tone"neutral" | "success" | "danger" | null | undefined"neutral"Border and focus-ring color. success and danger tint the border and focus ring; neutral keeps the default border.
placeholderstring"Choose a file"Text shown before a file is picked.
iconReact.ReactNode—Leading icon element. When omitted, a lucide Paperclip is rendered. Remixicon <i> elements are also supported.
clearablebooleantrueWhen true, shows a clear button once a file is selected. Set to false to hide it.
onChangeReact.ChangeEventHandler<HTMLInputElement>—Called with the native change event after the internal file name state is updated.
classNamestring—Additional classes merged into the outer label element via cn.
acceptstring—Inherited from input props. Restricts selectable file types, such as image/* or .pdf.
multipleboolean—Inherited from input props. Allows selecting more than one file; the field then shows a count.
namestring—Inherited from input props. Form field name used on submit.
disabledboolean—Inherited from input props. Disables the native input and dims the surface.
requiredboolean—Inherited from input props. Marks the native input as required for form validation.
aria-invalidboolean | "true" | "false" | "grammar" | "spelling"—Inherited from input props. When true, applies the danger border styling.

Accessibility

  • The native input is kept in the DOM with sr-only, so keyboard, form submission, and assistive technology use the real file input.
  • Clicking the label opens the file dialog; the label wraps the input, so the whole surface is a click target.
  • Focus visibility is shown on the label through has-[input:focus-visible], producing a ring when the hidden input is focused.
  • The leading icon is aria-hidden, so screen readers do not announce decorative icons.
  • The clear button has aria-label "Clear selected file" and type="button" so it does not submit the form. Its click handler stops propagation so the file dialog does not reopen.
  • Pass aria-invalid and required to the component for validation state; the danger border is applied automatically when aria-invalid is true.
  • Provide a visible label or an aria-label through the surrounding form field, because the placeholder text is not a substitute for a field name.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "File Input" component (ai2/file-input) from its shadcn registry.1. Install it with: npx shadcn@latest add @ai2/file-input2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: variant, size, tone, placeholder, icon, clearable, onChange, className, accept, multiple, name, disabled, required, aria-invalid.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { FileInput } from "@/components/ui/file-input"export function Example() {  return <FileInput name="attachment" accept="application/pdf" />}```

Files & dependencies

  • registry/ai2/ui/file-input.tsx
dependenciesclass-variance-authority@^0.7.1lucide-react@^1.23.0
registryDependencies@ai2/tokens

Looks similar, elsewhere