# File field

- **[Atoms](/components/)**

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

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

- **CLI**

  ```
  npx shadcn add @klarhimmel/file-field
  ```
- **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.

## Examples

- **Basic**

  ```
  import { FileField } from '@/components/klarhimmel/ui/file-field';
  
  export default function FileFieldBasic() {
    return (
      <div className="flex w-full max-w-md flex-col gap-5">
        <FileField label="Logo" accept="image/png,image/svg+xml" hint="PNG or SVG, up to 2 MB." />
        <FileField label="Room photos" multiple accept="image/*" hint="Pick as many as you like." />
      </div>
    );
  }
  ```
- **Error**

  ```
  import { FileField } from '@/components/klarhimmel/ui/file-field';
  
  export default function FileFieldError() {
    return (
      <div className="flex w-full max-w-md flex-col gap-5">
        <FileField label="Price list" accept="application/pdf" error="The file is larger than 2 MB. Choose a smaller PDF." />
        <FileField label="Contract" disabled hint="Uploads are locked while the booking is confirmed." />
      </div>
    );
  }
  ```

## Props

- **label**: Required. The visible label and the button's name.
- **hint**: Help text; an error replaces it and is read as the description.
- **error**: Replaces the hint and is announced as the description.
- **accept**: Passed to the native input.
- **multiple**: Passed to the native input.
- **disabled**: Prevents interaction.
- **name**: Form field name; the native input stays in the DOM (hidden), so a surrounding <form> submits the files.
- **onFiles**: Called with the chosen files.
- **buttonLabel**: Pass these translated; the English defaults are only a fallback.
- **emptyLabel**: Pass these translated.
- **className**: Extra classes, merged after the component's own.

## Accessibility

- Enter / Space · Opens the file picker
- Tab · Moves focus

[Accessibility](/get-started/accessibility)

The chosen names are announced when they change.

[Previous](/components/answer-form)

[Next](/components/menu)
