# Date field

A day picked from a calendar or typed in words, one way to write it everywhere, and a day with its clock time.

Live variants: https://design.arcadia.is/components/date-field

```tsx
import { DateField, DateTimeField, Calendar, formatDay } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import { Field, DateField } from "@arcadia/ui";

function Due() {
  const [due, setDue] = useState<string | null>("2026-11-21");
  const [refused, setRefused] = useState(false);
  return (
    <div {...sx("cmp-form", cmp.form)}>
      <Field label="Due date" error={refused ? "Type Nov 17, 2026 or a later date" : undefined}>
        <DateField value={due} onChange={(d) => { setDue(d); setRefused(false); }} onRefuse={() => setRefused(true)}
          today={TODAY} locale="en-US" min="2026-11-17" />
      </Field>
    </div>
  );
}
```

## With a time

```tsx
import { useState } from "react";
import { Field, DateTimeField } from "@arcadia/ui";

function WindowStart() {
  const [startsAt, setStartsAt] = useState<number | null>(SAMPLE_MS);
  return (
    <div {...sx("cmp-form", cmp.form)}>
      <Field label="Maintenance starts">
        <DateTimeField value={startsAt} onChange={setStartsAt} min={SAMPLE_MS - 3_600_000} aria-label="Maintenance starts" />
      </Field>
    </div>
  );
}
```

## Accessibility

The field is a combobox that opens a dialog: `aria-expanded` says whether the calendar shows. A click leaves the caret in the field; the down arrow moves focus onto the picked day, or today. The calendar is a `grid` labelled by its month, which is a live region, so a new month is read when it changes. Each day is named in full (Saturday, November 21, 2026), today is `aria-current`, the picked day `aria-selected`; with a range the grid is `aria-multiselectable` and every day of it is selected. Under forced colours, which drop every fill and shadow, the picked day and each day of a range stand on the system's highlight and today keeps its outline.

- ↓: In the field: open the calendar, focus on its day
- ← + →: A day back or on
- ↑ + ↓: A week back or on
- Page Up + Page Down: A month back or on, a year with Shift
- Home + End: The week's first or last day
- Enter + Space: Pick the day
- Esc: Close the calendar, focus back in the field

`DateTimeField` is a `group` described by its zone line. Inside a `Field` the label names the day's field, and the time field has its own id. Only the field that refused the edit is marked invalid. A clock outside `min` and `max`, emptied where `clearable` is `false`, or one the zone skips when its clocks go forward is refused: the value stays and an alert says why. A day the held clock cannot take saves nothing and asks for another time first. Where clocks go back, a clock that comes twice keeps its instant until another is typed.

## API reference

### DateField

- `value` (`Day | null`, required): The day, `YYYY-MM-DD`, or none.
- `onChange` (`(day: Day | null) => void`, required): Called with the day picked or typed (every typed day that reads, the same one too), or null when cleared.
- `onRefuse` (`(text: string) => void`): Called with a typed text it cannot read, or a day past `min` or `max`: the field keeps its day and is marked invalid until the text changes, and the product gives the error line through `Field`'s `error`.
- `min` (`Day`): The first day that can be picked or typed.
- `max` (`Day`): The last day that can be picked or typed.
- `today` (`Day`): The day it is, given by the product so a test and a server agree. Default: the machine's own day.
- `locale` (`string`): The reader's locale: the day's words, the month names it reads, the calendar's week. Default: the platform's.
- `size` (`"sm" | "md" | "lg"`, default `"md"`): Beside an `Input` of the same size.
- `variant` (`"default" | "ghost" | "bar" | "edge"`)
- `invalid` (`boolean`): Marks it invalid; a surrounding `Field` with `error` does it too.
- `clearable` (`boolean`): `false`: no clear control, and an emptied text keeps the day.
- `revealClearOnInteraction` (`boolean`)
- `rootStyle` (`InputStyle`): Typed StyleX override for the field's frame: where it sits and `Input`'s `--input-*` knobs.

Rest props go to `<input>` props.

### DateTimeField

- `value` (`number | null`, required)
- `onChange` (`(ms: number | null) => void`, required)
- `defaultTime` (`string`, default `"17:00"`)
- `min` (`number`)
- `max` (`number`)
- `clearable` (`boolean`, default `true`)
- `size` (`"sm" | "md" | "lg"`, default `"md"`): The text style it stands in and its height, as `Input`'s: `sm` 24px Caption, `md` 28px Body, `lg` 32px Headline.
- `invalid` (`boolean`)
- `showZone` (`boolean`, default `true`)
- `aria-label` (`string`)
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).

### Calendar

- `value` (`Day | null`, default `null`): The day picked, `YYYY-MM-DD`, or none.
- `range` (`{ first: Day; last?: Day | null } | null`): A range of days in the place of one: every day from `first` to `last` is chosen, the two ends among them, and `first` alone while the last is still to be pressed. `value` is not read beside it.
- `onChange` (`(day: Day) => void`): Called with the day a person picks: a click, or Enter or Space on it.
- `min` (`Day`): The first day that can be picked; days before it are drawn disabled and the keys skip them.
- `max` (`Day`): The last day that can be picked.
- `today` (`Day`): The day it is, given by the product so a test and a server agree. Default: the machine's own day.
- `locale` (`string`): The reader's locale: the names of months and days, and the week's first day (its week info, Monday where the platform says nothing). Default: the platform's.
- `rootStyle` (`RootStyle`): Typed StyleX override: where the calendar sits.

Rest props go to `<div>` props.
