Skip to content
// EFFECT DAYS 2026

FileDrop unstable

A headless file drop zone and picker trigger with shared accept, multiple and maxSize filtering, drag-over state, and Picked / Rejected events. Values stay controlled by the consumer: keep plain facts (names, sizes) in your Model and pass File values to Commands.

Anatomy

Part Element
root any element, usually a <div> or <section>
trigger <button> that opens the browser file picker

No part adds markup. Because root accepts any element, it can wrap trigger or stack with it on a single <button>: fileDrop.root(fileDrop.trigger(field.control(h.button))).

Always draw trigger for keyboard and screen-reader users: drag-and-drop alone has no pointer-free equivalent.

Data attributes

Present with an empty value or absent:

  • root: data-drag-over, data-disabled
  • trigger: data-disabled

Keyboard

trigger is a native <button type="button">, so Enter and Space open the picker and Tab moves focus.

Batch rules

Drops and HtmlFiles.pick results share one classifier:

  1. Empty batches (dismissed or blocked pickers, empty drops) emit nothing.
  2. When multiple is not true and more than one file arrives, the whole batch emits only Rejected with reason: "too-many-files".
  3. Otherwise each file is checked against accept, then maxSize. Nonempty groups emit in order: Picked, Rejected with reason: "invalid-type", then Rejected with reason: "file-too-large". Clearing an error on Picked and setting it on Rejected preserves the rejection message.

With Field, Fieldset and Form

Compose fileDrop.trigger(field.control(h.button)) with disabled: field.disabled (or fieldset.disabled). The field's label, aria-describedby and aria-invalid land on the button so Form focuses it after an invalid submit; pass disabled through because <fieldset disabled> does not block drops on a <div>. No hidden input is rendered because Form submits strings only.

Example

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Field, FileDrop } from "effect/ui/kit"
import { ByteSize, Effect, Schema } from "effect"
const Message = UiSchema.TaggedEnum({
PickedImages: { names: Schema.Array(Schema.String) },
RejectedImages: { reason: Schema.String }
})
const Upload = Html.component({
name: "Upload",
model: Schema.Struct({ names: Schema.Array(Schema.String), error: Schema.NullOr(Schema.String) }),
message: Message
}).make({
init: () => ({ names: [], error: null }),
update: {
PickedImages: ($, { names }) => ({ names: [...$.model.names, ...names], error: null }),
RejectedImages: ($, { reason }) => $.evolve({ error: reason })
},
view: (h, model) =>
Field(h, {
props: { invalid: model.error !== null },
view: (field) =>
FileDrop(h, {
props: {
accept: ["image/*"],
multiple: true,
maxSize: ByteSize.mebibytes(5),
disabled: field.disabled
},
onEmit: {
Picked: ({ files }) => Message.PickedImages({ names: files.map((file) => file.name) }),
Rejected: ({ reason }) => Message.RejectedImages({ reason })
},
view: (fileDrop) =>
field.root(h.div).children(
field.label(h.label).children("Photos"),
fileDrop.root(h.div.class("dropzone")).children(
fileDrop.trigger(field.control(h.button)).children("Choose photos")
),
field.error(h.div)?.children(model.error ?? "")
)
})
})
})
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Upload, {}))
if (!/<button[^>]* type="button"[^>]*>Choose photos<\/button>/.test(html)) {
throw new Error("the file drop trigger wasn't rendered as a button")
}
7 exports Since v4.2.0 Source

Components

FileDrop

unstable
Since v4.2.0

A headless file drop zone and picker trigger.

Details

parts also exposes dragOver and disabled booleans. Own attributes win over attributes set before the part: data-drag-over and data-disabled on root; type="button", disabled, aria-disabled (removed) and data-disabled on trigger. History restore is off (restore: false).

Signature

declare const FileDrop: Headless<{
readonly accept?: readonly Array<string>;
readonly disabled?: boolean;
readonly maxSize?: ByteSize;
readonly multiple?: boolean;
}, {
readonly _tag: "Picked";
readonly files: readonly Array<File>;
} | {
readonly _tag: "Rejected";
readonly files: readonly Array<File>;
readonly reason: "too-many-files" | "invalid-type" | "file-too-large";
}, {
disabled: boolean;
dragOver: boolean;
root: Part<string, [], never>;
trigger: Part<"button", [], never>;
}, never, never, never, never, never, never, {
readonly dragOver: boolean;
}, {
readonly _tag: "ClickedTrigger";
} | {
readonly _tag: "Left";
} | {
readonly _tag: "Entered";
} | {
readonly _tag: "Dropped";
readonly files: readonly Array<File>;
} | {
readonly _tag: "CompletedPick";
readonly files: readonly Array<File>;
}, QueryEntries<{}, {}>>

Models

FileDropEvents

type unstable
Since v4.2.0

What a FileDrop emits.

Signature

type FileDropEvents = typeof FileDropEvents.Type

FileDropProps

type unstable
Since v4.2.0

The props of a FileDrop.

Signature

type FileDropProps = typeof FileDropProps.Type
Since v4.2.0

Why FileDrop rejected a file batch.

Signature

type FileDropRejectReason = typeof FileDropRejectReason.Type

Schemas

Since v4.2.0

Events a FileDrop emits: Picked for accepted files and Rejected for files rejected for count, type or size.

Signature

declare const FileDropEvents: TaggedEnum<{
Picked: TaggedStruct<"Picked", {
readonly files: $Array<declare<File, File>>;
}>;
Rejected: TaggedStruct<"Rejected", {
readonly files: $Array<declare<File, File>>;
readonly reason: Literals<readonly ["too-many-files", "invalid-type", "file-too-large"]>;
}>;
}>
Since v4.2.0

Props for a FileDrop.

Details

  • accept: file types allowed for drops and passed to HtmlFiles.pick, matched without case: .ext suffix, type/* prefix, wildcard for any file, or exact type/subtype (ignoring ;... parameters). Omitted or empty allows every file.
  • multiple: allows more than one file per drop or pick (false by default).
  • maxSize: inclusive per-file limit as a ByteSize, such as ByteSize.mebibytes(5). No limit when omitted.
  • disabled: disables trigger, sets data-disabled, hides data-drag-over and ignores drags, drops and picks. root keeps its drop target so the browser does not open a dropped file in the tab.

Signature

declare const FileDropProps: Struct<{
readonly accept: optional<$Array<String>>;
readonly disabled: optional<Boolean>;
readonly maxSize: optional<ByteSize>;
readonly multiple: optional<Boolean>;
}>
Since v4.2.0

Why FileDrop rejected a file batch.

Signature

declare const FileDropRejectReason: Literals<readonly ["too-many-files", "invalid-type", "file-too-large"]>