Todae

Todae

Field.DateInput

Field.DateInput is a text input inside a Field that people type a date into, in the locale's own way. Its value is a Temporal.PlainDate or null. It reads the text when it is committed, on blur, on Enter or when its form is submitted, rewrites it as formatDate writes the date and calls onValueChange with it. Typing alone calls nothing. Without onValueChange, the input is read-only. It takes min, max, required, locale and placeholder, and the native input attributes that don't contradict them.

On this page
import { Calendar, Field, Label } from '@tounsoo/todae';
import { useId, useState } from 'react';

// The input and the calendar share one value, so typing and picking stay in step.
export default function FieldDateInputPicker({ locale }: { locale: string }) {
  const id = useId();
  const [date, setDate] = useState<Temporal.PlainDate | null>(null);
  return (
    <Field.Group>
      <Label.Root htmlFor={id}>Start date</Label.Root>
      <Field.Root id={id} name="start">
        <Field.DateInput value={date} onValueChange={setDate} locale={locale} />
        <Field.Picker>
          <Calendar.Root aria-label="Start date" value={date} onValueChange={setDate} locale={locale}>
            <Calendar.Header />
            <Calendar.Grid />
          </Calendar.Root>
        </Field.Picker>
      </Field.Root>
    </Field.Group>
  );
}

Here a Field.Picker beside the input opens a Calendar in a Popover. The input and the calendar get the same value and onValueChange, so a typed date moves the calendar to its month, and a picked date is written into the text and closes the popover. The panel's value is yours to pass: the picker only opens and closes it. Beside a Field.DateInput, the picker's button shows a calendar glyph and is named from the datePicker string.

Typed dates

formatDate writes a date in the locale's numbers, such as 10/13/2026 in en-US, and parseDate reads one typed in the locale's numbers or words, such as Oct 13, 2026. formatDate and parseDate says what each writes and reads.

Field.DateInput reads its text with parseDate and writes it with formatDate, in its locale. Empty text commits null. Text that is not a date stays as it was typed, onValueChange is not called, and the field is marked invalid once a commit has tried to read it; until the text is a date or empty, the form can't be submitted. A value the product sets while someone types replaces the text, and a reset of the form drops it. For a text input of your own, formatDate and parseDate work in a Field.TextInput too.

On its own

On its own, Field.DateInput is the field's control, with no button. People who know the date by heart type it, and the text is rewritten in the locale's numbers once they leave the input.

import { Code, Field, Label, Stack } from '@tounsoo/todae';
import { useId, useState } from 'react';

// The value changes when the text is committed: on blur, on Enter, or when the form is submitted.
export default function FieldDateInputAlone({ locale }: { locale: string }) {
  const id = useId();
  const [birthday, setBirthday] = useState<Temporal.PlainDate | null>(null);
  return (
    <Stack.Root gap="condensed">
      <Field.Group>
        <Label.Root htmlFor={id}>Date of birth</Label.Root>
        <Field.Root id={id} name="birthday">
          <Field.DateInput value={birthday} onValueChange={setBirthday} locale={locale} />
        </Field.Root>
      </Field.Group>
      <Code.Root>{birthday ? birthday.toString() : 'null'}</Code.Root>
    </Stack.Root>
  );
}
null

The date goes with a form in a native <input type="date"> beside the text input, under the field's name, or the input's own name, the way HTML writes a date, such as 2026-10-13. The text input sends nothing. The native input is hidden from sight and from assistive technology and is not a tab stop. required makes a form with no date invalid, and min and max make a form with an earlier or later date invalid; the browser checks all three on the native input. Text that is not a date blocks the submit too. Inside a Form.Root, a problem shows in the field's ErrorMessage.Root in the page's language, with min or max written as formatDate writes a date, and focus goes to the text input. Outside a Form.Root the browser blocks the submit and focus lands on the text input too. A native date input holds only the years 1 to 275760, so a value or bound outside them reads as no date: it is sent empty, required, min and max ignore it, and development builds warn once. A Calendar's isDateDisabled is not part of the check: a typed date it rules out is still a date, so check it yourself and set customValidity on the Field.Root.

Accessible composition

Todae handles: The text input takes id, aria-label, aria-labelledby and aria-describedby from Field.Root, and native disabled and aria-invalid from the Root or a surrounding Fieldset. It gets aria-invalid once a commit can't read its text, and aria-required with required. Enter during an IME composition commits nothing. Beside a Field.Picker, the input stays the field's control, and the picker's button is named from the datePicker string in StringsProvider and shows the calendar glyph from GlyphsProvider. Read-only, a press on the input opens the picker.

You supply: A name, through a Label whose htmlFor is the Root id or aria-label / aria-labelledby on the Root. The same date for the input and a Calendar beside it, and the same locale, min and max.

Watch for: With a value, the server writes the date in its own locale, so pass locale when the input renders on a server. Text that reads as a date but not the one meant, such as a two-digit year read as the nearest such year: show the date in words nearby when that matters.

When to use

Field.DateInput

When: A date in a form, typed or, with a Field.Picker and a Calendar beside it, picked from a month, such as a deadline, a booking or a birthday.

When not: A calendar shown on the page → Calendar. A start and an end date → Field.DateRangeInput. A date with a time → Field.DateTimeInput.

Props

Field.DateInput props
NameTypeDescription
value RequiredTemporal.PlainDate | null

The date, or null for none.

onValueChange(value: Temporal.PlainDate | null) => void

Fires on a person's commit, on blur, Enter or a submit of the form, with the date the text says, read with parseDate, or null for an empty text. Typing alone fires nothing, and text that is no date stays, invalid. Without it the input is read-only.

minTemporal.PlainDate

The earliest date. A form with an earlier date is invalid.

maxTemporal.PlainDate

The latest date. A form with a later date is invalid.

requiredboolean

A form with no date is invalid.

localestring

The locale the text is read and written in, such as "ko". The browser's own when not set, so pass it when the input renders on a server.

placeholderstring

Native placeholder.