Todae

Todae

Field.DateRangeInput

Field.DateRangeInput is a text input inside a Field that people type a range of dates into, two dates with a separator between them. Its value is a DateRange, { start, end } with both days included, or null. It reads the text when it is committed, on blur, on Enter or when its form is submitted, rewrites it as formatDateRange writes the range and calls onValueChange with it. Typing alone calls nothing. Without onValueChange, the input is read-only. It works like Field.DateInput and takes the same props where they mean the same thing.

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

// The input and the calendar share one range, so typing and picking stay in step.
export default function FieldDateRangeInputPicker({ locale }: { locale: string }) {
  const id = useId();
  const [stay, setStay] = useState<DateRange | null>(null);
  return (
    <Field.Group>
      <Label.Root htmlFor={id}>Stay</Label.Root>
      <Field.Root id={id} name="stay">
        <Field.DateRangeInput value={stay} onValueChange={setStay} locale={locale} />
        <Field.Picker>
          <Calendar.Root aria-label="Stay" mode="range" value={stay} onValueChange={setStay} locale={locale}>
            <Calendar.Header />
            <Calendar.Grid />
          </Calendar.Root>
        </Field.Picker>
      </Field.Root>
    </Field.Group>
  );
}

Here a Field.Picker beside the input opens a Calendar with mode="range" in a Popover. The input and the calendar get the same value and onValueChange, so a typed range moves the calendar to its start. The first date picked in the calendar starts a range and the second ends it, in either order; the range is then written into the text and the popover closes. After the first pick, Escape drops it and the calendar stays open. Beside a Field.DateRangeInput, the picker's button shows a calendar glyph and is named from the dateRangePicker string.

Typed ranges

formatDateRange writes both dates as formatDate writes them, with the locale's range separator between them, such as 10/3/2026 – 10/10/2026 in en-US, and parseDateRange reads two dates typed with a separator between them, such as Oct 3, 2026 – Oct 10, 2026 or 2026-10-03/2026-10-10. formatDateRange and parseDateRange says what each writes and reads.

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

Presets such as "Last 7 days" are not part of the input. They are the Date range with presets recipe, which puts buttons beside the field that set its value.

On its own

On its own, Field.DateRangeInput is the field's control, with no button, for a range people know the dates of.

import { Code, Field, Label, Stack, type DateRange } 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 FieldDateRangeInputAlone({ locale }: { locale: string }) {
  const id = useId();
  const [period, setPeriod] = useState<DateRange | null>(null);
  return (
    <Stack.Root gap="condensed">
      <Field.Group>
        <Label.Root htmlFor={id}>Report period</Label.Root>
        <Field.Root id={id} name="period">
          <Field.DateRangeInput value={period} onValueChange={setPeriod} locale={locale} />
        </Field.Root>
      </Field.Group>
      <Code.Root>{period ? `${period.start}/${period.end}` : 'null'}</Code.Root>
    </Stack.Root>
  );
}
null

The range goes with a form in a native text input beside the text input, under the field's name, or the input's own name, as an ISO 8601 interval such as 2026-10-03/2026-10-10. 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 range invalid. No native input holds a range, so the browser does not check min and max: the input does, and a range that starts before min or ends after max blocks the submit, as text that is not a range does. Inside a Form.Root, a missing range shows in the field's ErrorMessage.Root in the page's language, a range that starts before min or ends after max shows the dateRangeUnderflow or dateRangeOverflow string with the bound in the input's own date format, and unreadable text shows the badInput string; focus goes to the text input. Outside a Form.Root the browser blocks the submit and focus lands on the text input too. A Calendar's isDateDisabled is not part of the check, and neither is whether every day between the dates can be picked, so check a typed range 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. Beside a Field.Picker, the input stays the field's control, and the picker's button is named from the dateRangePicker string in StringsProvider and shows the calendar glyph from GlyphsProvider. The calendar inside is keyed and announced as on Calendar in range mode.

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

Watch for: With a value, the server writes the range in its own locale, so pass locale when the input renders on a server.

When to use

Field.DateRangeInput

When: A start and an end date in a form, such as a stay, a trip or a report's period.

When not: One date → Field.DateInput. A range picked from a calendar shown on the page → Calendar with mode="range". A start and an end that people set apart, such as a start date and a separate deadline → two Field.DateInputs.

Props

Field.DateRangeInput props
NameTypeDescription
value RequiredDateRange | null

The range, or null for none.

onValueChange(value: DateRange | null) => void

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

minTemporal.PlainDate

The earliest date the range can hold. A form with a range that starts earlier is invalid.

maxTemporal.PlainDate

The latest date the range can hold. A form with a range that ends later is invalid.

requiredboolean

A form with no range 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.