Skip to content
Klarhimmel UI

File field

No file chosen

PNG or SVG, up to 2 MB.

npx shadcn add @klarhimmel/file-field

Examples

  • 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.

file-field.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { FileField } from '@/components/klarhimmel/ui/file-field';

export default function Example() {
  return (
    <Theme theme="brand">
      <FileField label="Logo" accept="image/png,image/svg+xml" hint="PNG or SVG, up to 2 MB." onFiles={(files) => console.log(files)} />
    </Theme>
  );
}

Import

Import

import { FileField } from '@/components/klarhimmel/ui/file-field';
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

PropTypeDefaultDescription
labelReactNoderequiredRequired. The visible label and the button's name.
hintReactNode-Help text; an error replaces it and is read as the description.
errorReactNode-Replaces the hint and is announced as the description.
acceptstring-Passed to the native input.
multipleboolean-Passed to the native input.
disabledboolean-Prevents interaction.
namestring-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.
buttonLabelReactNode'Choose file'Pass these translated; the English defaults are only a fallback.
emptyLabelReactNode'No file chosen'Pass these translated.
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
Enter / SpaceOpens the file picker
TabMoves focus

The chosen names are announced when they change.

Accessibility