UI componentsdocs/ui/components/files.md

Files & uploads

Choose, drop, upload and show files.

← Component reference

File inputs #

Choose or drop files.

FileInput #

Native file input.

<FileInput aria-label="Attachment" />
PropTypeRequiredDefaultDescription
acceptstringAllowed file types, e.g. image/*,.pdf.
disabledbooleanDisables the field.
invalidbooleanMarks the value invalid (aria-invalid and error styling).
multiplebooleanAllow choosing several files.
namestringField name submitted with the form.
onChange(e: Event) => voidCalled when the selection changes; read e.target.files.
requiredbooleanA file must be chosen before the form submits.

FileButton #

Hidden file input triggered by a button (Mantine FileButton).

No file chosen

function Example() {
    const file = signal("");
    return (
        <Group gap="0.75rem">
            <FileButton accept="image/*" onChange={(files) => file.set(files[0]?.name ?? "")}>
                Upload avatar
            </FileButton>
            <Text muted>{file() || "No file chosen"}</Text>
        </Group>
    );
}

Slots: root input label

PropTypeRequiredDefaultDescription
onChange(files: File[]) => voidyesCalled with the chosen files.
acceptstringAllowed file types, e.g. image/*,.pdf.
childrencontent"Choose file"Button label.
disabledbooleanDisables the button.
multiplebooleanAllow choosing several files.

Dropzone #

Drag-and-drop file target (also a click-to-browse file input).

No files yet

function Example() {
    const files = signal<string[]>([]);
    return (
        <Stack gap="0.5rem">
            <Dropzone
                multiple
                accept=".csv"
                onDrop={(dropped) => files.set(dropped.map((f) => f.name))}
            >
                Drop CSV files here, or click to browse
            </Dropzone>
            <Text muted>{files().length ? files().join(", ") : "No files yet"}</Text>
        </Stack>
    );
}

Slots: root input label

PropTypeRequiredDefaultDescription
onDrop(files: File[]) => voidyesCalled with the dropped or chosen files.
acceptstringAllowed file types, e.g. image/*,.pdf; other files are ignored.
childrencontentInstructions shown in the drop area.
disabledbooleanIgnore drops and clicks.
multiplebooleanAccept several files at once.

Also accepts the shared props: pass-through attributes, class, style, classes, styles, unstyled.

File items #

Uploads in progress and attached files.

UploadItem #

File upload row with progress.

function Example() {
    const progress = signal(12);
    const cancelled = signal(false);
    // Simulated upload; effects run only in the browser.
    effect(() => {
        const timer = setInterval(() => {
            if (!cancelled() && progress() < 100) progress.set(Math.min(100, progress() + 8));
        }, 400);
        return () => clearInterval(timer);
    });
    return (
        <Show
            when={!cancelled()}
            fallback={
                <Button
                    size="sm"
                    variant="outline"
                    onClick={() => {
                        progress.set(0);
                        cancelled.set(false);
                    }}
                >
                    Upload again
                </Button>
            }
        >
            <UploadItem
                name="[email protected]"
                progress={progress()}
                onCancel={() => cancelled.set(true)}
            />
        </Show>
    );
}

Slots: root bar cancel name row status track

PropTypeRequiredDefaultDescription
namestringyesFile name.
progressnumberyesUpload progress in percent (0–100).
errorstringError message; shows the failed state.
onCancel() => voidShows a cancel button; called when it is pressed.

FileCard #

Attached file with icon, name, metadata and remove action.

Q3-report.pdf2.4 MB · PDF
function Example() {
    const attached = signal(true);
    return (
        <Show
            when={attached()}
            fallback={
                <Button size="sm" variant="outline" onClick={() => attached.set(true)}>
                    Attach Q3-report.pdf
                </Button>
            }
        >
            <FileCard
                name="Q3-report.pdf"
                meta="2.4 MB · PDF"
                onRemove={() => attached.set(false)}
            />
        </Show>
    );
}

Slots: root icon meta name remove text

PropTypeRequiredDefaultDescription
namestringyesFile name.
iconIconName"file"File icon.
metastringSmall line, e.g. size and type.
onRemove() => voidShows a remove button; called when it is pressed.

IconName — Material Design Icons path names used by <Icon />.

type IconName = | "check" | "x" | "plus" | "minus" | "search" | "user" | "users" | "settings" | "menu" | "home" | "heart" | "star" | "bell" | "mail" | "calendar" | "clock" | "edit" | "trash" | "copy" | "download" | "upload" | "link" | "external" | "info" | "warning" | "error" | "success" | "chevron-down" | "chevron-up" | "chevron-left" | "chevron-right" | "arrow-left" | "arrow-right" | "eye" | "eye-off" | "eye-outline" | "lock" | "unlock" | "filter" | "more" | "close" | "spinner" | "sun" | "moon" | "play" | "pause" | "refresh" | "share" | "image" | "file" | "folder" | "zap" | "phone" | "git" | "code";

Also accepts the shared props: pass-through attributes, class, style, classes, styles, unstyled.