DateField unstable
A controlled text input for a calendar date. Pass the current date as
value, a DateTime or null for an empty field, and store the
DateTime.Utc | null that Committed carries. Your view supplies the
<input> builder; the component formats and parses its text for a locale.
The component keeps draft text while the user types.
Anatomy
| Part | Element |
|---|---|
input |
<input>, the editable date field |
input takes the consumer's <input> builder and returns it, so you can
chain classes, attributes and handlers. It wraps the element in a
<span style="display:contents">, which also holds the hidden form input
when name is set.
The parts also return value (normalized DateTime.Utc | null),
inputValue (the text the input shows), pattern (the locale's pattern,
such as "dd/mm/yyyy", for a placeholder or hint), disabled, readOnly
and required.
Date values
value accepts any DateTime and is normalized to midnight UTC with
DateTime.removeTime: a Zoned value gives its day in its own time zone,
and a Utc value its UTC day. A Utc "now" therefore gives the UTC day,
so derive "today" from DateTime.nowInCurrentZone or another zoned value.
Dates are formatted in UTC, so the printed day cannot shift.
Parsing
The field reads the locale's numeric order, taken from
Intl.DateTimeFormat#formatToParts with a 4-digit year and any suffix such
as Bulgarian ะณ., and ISO YYYY-MM-DD, which wins when both match. Dates
that do not exist, such as 31/02/2026, are rejected. The displayed text
always parses back: years have 4 digits, and a locale whose dates look like
ISO in another order (Kyrgyz yyyy-dd-mm) shows / in place of -.
Naming and validation
Name the input with a <label for>, an aria-label, or a Field: draw it
with dateField.input(field.control(h.input)) and pass
disabled: field.disabled. DateField never writes aria-invalid or id,
leaving validation and labelling to Field.
Data attributes
On input, each present with an empty value or absent:
data-disableddata-readonlydata-required
A Field's data attributes, such as data-invalid and data-touched, stay
on the input field.control decorates.
Keyboard
On input, Enter commits the typed text; text that does not parse stays in
the input. Enter is ignored while an input method is composing or with a
modifier key held.
Events
Committed carries { date: DateTime.Utc | null } when the user finishes
editing with blur or Enter and the parsed date differs from value. Empty
text commits null. On blur, text that does not parse commits nothing and
reverts to the formatted value.
Forms
When name is set, a hidden input submits the date as YYYY-MM-DD (""
when empty) and the visible input has no name. A disabled field submits
nothing.
The server formats with its own default locale, which may differ from the
browser's, so pass locale when rendering on a server.
Example A labelled date field whose value lives in the consumer's Model
import { UiSchema } from "effect/ui"import { Html, HtmlServer } from "effect/ui/html"import { DateField, Field } from "effect/ui/kit"import { DateTime, Effect, Schema } from "effect"
const EventMessage = UiSchema.TaggedEnum({ CommittedDate: { date: Schema.NullOr(Schema.DateTimeUtc) }})
const EventForm = Html.component({ name: "EventForm", model: Schema.Struct({ date: Schema.NullOr(Schema.DateTimeUtc) }), message: EventMessage}).make({ init: () => ({ date: DateTime.makeUnsafe({ year: 2026, month: 11, day: 26 }) }), update: { CommittedDate: ($, { date }) => $.evolve({ date }) }, view: (h, model) => Field(h, { view: (field) => DateField(h, { props: { value: model.date, locale: "en-GB", name: "date", disabled: field.disabled }, onEmit: { Committed: ({ date }) => EventMessage.CommittedDate({ date }) }, view: (dateField) => field.root(h.div).children( field.label(h.label).children("Date"), dateField.input(field.control(h.input.class("date"))).attr( "placeholder", dateField.pattern ) ) }) })})
// The input shows the formatted date and pattern; the hidden input carries ISO.const { html } = await Effect.runPromise(HtmlServer.renderToHtml(EventForm, {}))const input = /<input class="date" id="([^"]+)"[^>]*>/.exec(html)if (input === null || !html.includes('<label for="' + input[1] + '"')) throw new Error("the input isn't labelled")if (!input[0].includes('value="26/11/2026"')) throw new Error("the input doesn't show the formatted date")if (!input[0].includes('placeholder="dd/mm/yyyy"')) throw new Error("the placeholder doesn't show the pattern")if (!/<input[^>]*type="hidden"[^>]*name="date"[^>]*value="2026-11-26"/.test(html)) throw new Error("no ISO form value")Components
A headless date field. Call it with the consumer's h, the props, and a
view closure that draws the input with dateField.input(h.input).
Details
The field's own attributes win over the ones the consumer set on the builder before the part, including the ones a state leaves absent:
input:type,name(removed from the visible input so the hidden input submits the ISO date),form,required,readonly,disabled,aria-disabled(removed),data-disabled,data-readonly,data-requiredandvalue.
autocomplete, autocorrect and spellcheck are written only when the
builder has none. aria-invalid and id are never written, so Field
keeps full ownership of them.
The input handles input, blur and keydown on a layer of its
own, so the consumer's handlers for them, and a Field's, still run.
History restore saves nothing of it: after Back, forward or a reload it
starts from init.
Signature
declare const DateField: Headless<{ readonly disabled?: boolean; readonly form?: string; readonly locale?: string | readonly Array<string>; readonly name?: string; readonly readOnly?: boolean; readonly required?: boolean; readonly value: Utc | Zoned | null;}, { readonly _tag: "Committed"; readonly date: Utc | null;}, { disabled: boolean; input: Part<"input", [], never>; inputValue: string; pattern: string; readOnly: boolean; required: boolean; value: Utc | null;}, never, never, never, never, never, never, { readonly draft: string | null;}, { readonly _tag: "PressedEnter";} | { readonly _tag: "BlurredInput"; readonly disabled: boolean;} | { readonly _tag: "UpdatedInput"; readonly value: string;}, QueryEntries<{}, {}>>Models
Schemas
DateFieldEvents
unstableWhat a DateField emits.
Details
Committed: asks forvalueto bedate, aDateTime.Utcat midnight UTC, ornullwhen the field was cleared.
Signature
declare const DateFieldEvents: TaggedEnum<{ Committed: TaggedStruct<"Committed", { readonly date: NullOr<DateTimeUtc>; }>;}>DateFieldProps
unstableProps for a DateField.
Details
value: the date, anyDateTime, ornullfor an empty field.locale: the locale used to format, parse and derivepattern; the runtime's default when left out.name: the form field name for the hidden input carrying the ISO date.form: the id of the form that submits it, when the field is not inside one.disabled: disables both inputs and commits nothing.readOnly: keeps the input focusable and selectable but commits nothing.required: sets the nativerequiredattribute.
Signature
declare const DateFieldProps: Struct<{ readonly disabled: optional<Boolean>; readonly form: optional<String>; readonly locale: optional<Union<readonly [String, $Array<String>]>>; readonly name: optional<String>; readonly readOnly: optional<Boolean>; readonly required: optional<Boolean>; readonly value: NullOr<Union<readonly [DateTimeUtc, DateTimeZoned]>>;}>