A file input with a styled trigger button and drag-and-drop support.
import { FileInput } from '@bgunnarsson/react-primitives'| Prop | Type | Default | Description |
|---|---|---|---|
onFilesChange |
(files: File[]) => void |
— | Called with selected files after picking or dropping. |
accept |
string |
— | Accepted file types (e.g. 'image/*', '.pdf,.docx'). |
multiple |
boolean |
false |
Allow selecting multiple files. |
disabled |
boolean |
false |
Disables picking and dropping. |
children |
React.ReactNode |
'Choose file' |
Label rendered inside the trigger button. |
Also accepts React.HTMLAttributes<HTMLDivElement> on the outer container.
import { useState } from 'react'
const [files, setFiles] = useState<File[]>([])
<FileInput multiple accept="image/*" onFilesChange={setFiles}>
Upload images
</FileInput><FileInput
multiple
accept="image/*"
onFilesChange={setFiles}
className="flex flex-col items-center justify-center rounded-xl border-2 border-dashed border-gray-300 p-8 text-center transition-colors data-[dragging]:border-blue-500 data-[dragging]:bg-blue-50"
>
<span className="text-sm text-gray-500">
Drag & drop images here, or{' '}
<span className="font-medium text-blue-600 underline">browse</span>
</span>
</FileInput>- The actual
<input type="file">is hidden; clicking anywhere in the container (via the internal button) opens the file picker. data-draggingis set on the container while a file is dragged over it — use this for drag-hover styles.data-disabledis set whendisabled={true}.