Todae

Todae

Field.DateTimeInput

Field.DateTimeInput is a text input inside a Field that people type a date and a time into, in the locale's own way. Its value is a Temporal.PlainDateTime or null. It reads the text when it is committed, on blur, on Enter or when its form is submitted, rewrites it as formatDateTime writes the value and calls onValueChange with it. Typing alone calls nothing. Without onValueChange, the input is read-only. It works like Field.DateInput and Field.TimeInput, and takes the same props where they mean the same thing. A PlainDateTime has no time zone: it is the date and time on the user's clock. To store an instant, combine it with a time zone in your own code, such as value.toZonedDateTime(zone).

On this page
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 FieldDateTimeInputAlone({ locale }: { locale: string }) {
  const id = useId();
  const [departs, setDeparts] = useState<Temporal.PlainDateTime | null>(null);
  return (
    <Stack.Root gap="condensed">
      <Field.Group>
        <Label.Root htmlFor={id}>Departs</Label.Root>
        <Field.Root id={id} name="departs">
          <Field.DateTimeInput value={departs} onValueChange={setDeparts} locale={locale} />
        </Field.Root>
      </Field.Group>
      <Code.Root>{departs ? departs.toString() : 'null'}</Code.Root>
    </Stack.Root>
  );
}
null

On its own, Field.DateTimeInput is the field's control, with no button. To pick the value too, put a Field.Picker beside it with a Calendar and an OptionList of times. There is no date-and-time panel: the Date and time picker recipe composes one, keeping the time when a day is picked and the day when a time is picked, and closing the picker once both are set.

import { Calendar, Field, Label, OptionList, timeOptions } from '@tounsoo/todae';
import { useId, useState } from 'react';
import styles from './DateTimePicker.module.css';

// A day or a time picked while the other half is missing, held until the other is picked too.
type Halves = { date: Temporal.PlainDate | null; time: Temporal.PlainTime | null };
const NONE: Halves = { date: null, time: null };

export default function DateTimePicker({ locale }: { locale: string }) {
  const id = useId();
  const [starts, setStarts] = useState<Temporal.PlainDateTime | null>(null);
  const [held, setHeld] = useState<Halves>(NONE);
  const date = starts?.toPlainDate() ?? held.date;
  const time = starts?.toPlainTime() ?? held.time;

  // A pick keeps the other half, and makes the value, and closes the picker, once both are set.
  function pick(next: Halves, close: () => void) {
    const day = next.date ?? date;
    const at = next.time ?? time;
    if (day && at) {
/* The calendar and the times side by side, the times as tall as the calendar. */
.panel {
  display: flex;
  align-items: flex-start;
  gap: var(--todae-space-stack-gap);
}

/* The times scroll in their own box. The padding and scroll padding leave room
   for the list's focus ring, which the box would otherwise cut. */
.times {
  --_times-height: calc(6 * var(--todae-space-12));

  align-self: stretch;
  max-block-size: var(--_times-height);
  overflow-y: auto;
  padding: calc(var(--todae-focus-ring-width) + var(--todae-focus-ring-offset));
  scroll-padding: calc(var(--todae-focus-ring-width) + var(--todae-focus-ring-offset));
}

/* On a narrow screen the times go under the calendar, in a shorter box. */
@media (width < 32rem) {
  .panel {
    flex-direction: column;
    align-items: stretch;
  }

  .times {
    --_times-height: calc(3 * var(--todae-space-12));
  }
}

Typed dates and times

formatDateTime writes the date in numbers and the time in hours and minutes, such as 10/13/2026, 9:30 PM in en-US, and parseDateTime reads a date and a time typed in the order the locale writes them, such as Oct 13, 2026 at 9:30 PM. formatDateTime and parseDateTime says what each writes and reads.

Field.DateTimeInput reads its text with parseDateTime and writes it with formatDateTime, in its locale. Empty text commits null. Text that is not a date and time 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 and time or empty, the form can't be submitted.

In a form

The value goes with a form in a native <input type="datetime-local"> beside the text input, under the field's name, or the input's own name, the way HTML writes one, such as 2026-10-13T09:30. The text input sends nothing, and the native input is hidden from sight and from assistive technology and is not a tab stop. required makes a form with no value invalid, and min and max make a form with an earlier or later one invalid. The browser checks all three on the native input, and text that is not a date and time 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 formatDateTime writes them, 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 value: it is sent empty, required, min and max ignore it, and development builds warn once.

Temporal

Todae ships no Temporal polyfill. The input's value, formatDateTime and parseDateTime are Temporal.PlainDateTime, so where the browser has no Temporal, the app loads a polyfill (see Native platform). Todae's types need TypeScript 6 or later, which declares Temporal.

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. Beside a Field.Picker, the input stays the field's control, and the picker's button is named from the dateTimePicker string in StringsProvider and shows the calendar glyph from GlyphsProvider.

You supply: A name, through a Label whose htmlFor is the Root id or aria-label / aria-labelledby on the Root. With a picker, the panel and its names, as the recipe shows.

Watch for: With a value, the server writes the date and time in its own locale, so pass locale when the input renders on a server. A value stored as if it were an instant: a PlainDateTime moves with the reader's clock, so add the time zone before you store a moment.

When to use

Field.DateTimeInput

When: A date and a time of day in one value, such as when a meeting starts or a flight departs.

When not: A date alone → Field.DateInput. A time alone → Field.TimeInput. An instant in a time zone → this input, with the zone added in your own code.

Props

Field.DateTimeInput props
NameTypeDescription
value RequiredTemporal.PlainDateTime | null

The date and time, or null for none.

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

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

minTemporal.PlainDateTime

The earliest date and time. A form with an earlier one is invalid.

maxTemporal.PlainDateTime

The latest date and time. A form with a later one is invalid.

requiredboolean

A form with no date and time 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.