File field
No file chosen
PNG or SVG, up to 2 MB.
npx shadcn add @klarhimmel/file-fieldCopy for AIExamples
Chosen
Basic
Error
DetailsAbout, usage, props and more
A styled file picker: label, button, the chosen names, and a hint or an error. The native input stays in the form.
When to use
Use for
A form that takes an upload: logo, CV, photos.
Not for
Drag-and-drop galleries or large uploads with progress.
Pairs with
Field-style forms, Banner for a failed upload.
Preview
No file chosen
PDF, up to 2 MB each.
Import
Import
- Files
- file-field.tsx, in components/klarhimmel/ui/. With it: button, theme, utils. npm: lucide-react.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | required | Required. The visible label and the button's name. |
hint | ReactNode | - | Help text; an error replaces it and is read as the description. |
error | ReactNode | - | Replaces the hint and is announced as the description. |
accept | string | - | Passed to the native input. |
multiple | boolean | - | Passed to the native input. |
disabled | boolean | - | Prevents interaction. |
name | string | - | Form field name; the native input stays in the DOM (hidden), so a surrounding <form> submits the files. |
onFiles | (files: File[]) => void | - | Called with the chosen files. |
buttonLabel | ReactNode | 'Choose file' | Pass these translated; the English defaults are only a fallback. |
emptyLabel | ReactNode | 'No file chosen' | Pass these translated. |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Enter / Space | Opens the file picker |
Tab | Moves focus |
The chosen names are announced when they change.
Accessibility