Fragiola

Fields

File Upload

A form control holding a list of files: drop, paste or pick them, see each one's preview, size, progress or error.

npx shadcn@latest add @fragiola/file-upload
File Upload
Gallery

A file upload holds the files a form will submit. They arrive through the dialog (the Trigger, the Label, or a press on the Dropzone), a drop or a paste on the Dropzone. Each new file is checked, in order, by accept, maxFileSize, minFileSize, validate (your own reasons) and maxFiles: it joins the value (value, onValueChange) or the rejected list with its reasons (invalid-type, too-large, too-small, too-many, yours), reported by onFileReject. One file (maxFiles 1, the default) is a single file input: a new pick replaces it. The HiddenInput carries the files to the form (name, required, a form reset), and announcement returns the text a polite live region reads after each pick. A delete button removes its file and moves the focus to the next one.

It does not upload. Read the value (or the form's FormData) and send the files; the example simulates the transport with a timer and shows each file's progress with a Progress, on the track family, and a failed upload with the palette-danger class.

FileUpload.Template.Simple is the Label (label), the Dropzone with its icon, "Click to upload or drag and drop" and hint, the hidden input, and every file (accepted, then rejected with its first reason in English) with its delete button (aria-label="Delete photo.png" for a file "photo.png"). Every Root prop is forwarded; className goes to the root.

The look

It is the file family's, after Untitled UI's file upload. The Dropzone is the Drop Zone's target: a dashed line box, and the dashed ring drop outline while files are dragged over it. A file (Item) is a control box (foundation.box): a line stroke on a transparent background, with its ItemPreview (an image's thumbnail) or ItemIcon in a recessed soft square, its ItemName and its ItemSizeText (in the locale's units) or ItemError, and an ItemDeleteTrigger, a ghost square Clickable. A rejected file gets palette-danger from its state, as an invalid field does: a red stroke with red text, never a red block. ClearTrigger removes every file and hides while there is none.

Bases

Primitives-backed. Base UI has no file upload, so this is one shared file (ui/file-upload.tsx) that wraps Fragiola Primitives' FileUpload on both bases, and the item depends on @fragiola/[email protected] on both.

On Base UI, the registry's Field is Base UI's and does not reach a Fragiola Primitives control: name the group with FileUpload.Label, and pass name, required and disabled to the Root. On Fragiola Primitives it is also a Field control. The files reach the form by assigning them to the hidden input: verified in Chromium; Firefox and Safari accept the same assignment by the HTML standard.

Parts

PartSource
Rootprimitive FileUpload.Root (a group), a column
Labelprimitive FileUpload.Label + field.label()
Dropzoneprimitive FileUpload.Dropzone + file.dropZone()
DropzoneIconfile.icon()
Triggerprimitive FileUpload.Trigger + clickable() outline
HiddenInputprimitive FileUpload.HiddenInput
ItemGroupprimitive FileUpload.ItemGroup + file.list()
Itemprimitive FileUpload.Item + file.item(); file.rejected() from its state
ItemPreview, ItemPreviewImageprimitive parts + file.preview(), file.image()
ItemIconfile.preview(); a file icon by default
ItemTextfile.text()
ItemName, ItemSizeTextprimitive parts + file.name(), file.meta()
ItemErrorfile.meta()
ItemDeleteTriggerprimitive FileUpload.ItemDeleteTrigger + clickable(); a bin by default
ClearTriggerprimitive FileUpload.ClearTrigger + clickable() ghost
Template.Simplethe label, the dropzone, the hidden input and every file

On this page