# Date field

A typed date (or date and time) in the locale's order, with min/max and month-day mode.

- Family: date
- Import: `import { DateField } from "@senvenli/react/date";`
- Page: https://design.senvenli.com/docs/components/date-field
- JSON: https://design.senvenli.com/docs/components/date-field.json

## Example: A typed date

Segments in the locale's order; arrow keys step each one.

```tsx
import { CalendarDate } from "@internationalized/date";
import { DateField } from "@senvenli/react/date";

export default function Example() {
  return <DateField label="Delivery date" defaultValue={new CalendarDate(2026, 3, 18)} />;
}
```

## Examples

### With a range

`minValue` and `maxValue` bound what can be typed; a date outside says so.

```tsx
import { CalendarDate } from "@internationalized/date";
import { DateField } from "@senvenli/react/date";

export default function Example() {
  return (
    <DateField
      label="Invoice date"
      description="Any day in the first quarter of 2026."
      defaultValue={new CalendarDate(2026, 3, 18)}
      minValue={new CalendarDate(2026, 1, 1)}
      maxValue={new CalendarDate(2026, 3, 31)}
      isRequired
    />
  );
}
```

### Month and year

A card's expiry: no day, and the value is the month's first day.

```tsx
import { CalendarDate } from "@internationalized/date";
import { DateField } from "@senvenli/react/date";

export default function Example() {
  return <DateField label="Card expiry" granularity="month" defaultValue={new CalendarDate(2028, 9, 1)} />;
}
```

### Day and month

A yearly date with no year, such as a birthday reminder.

```tsx
import { CalendarDate } from "@internationalized/date";
import { DateField } from "@senvenli/react/date";

export default function Example() {
  // The value's year is always 2000, a leap year, so February 29 can be typed.
  return <DateField label="Birthday" description="We send a discount code every year." hideYear defaultValue={new CalendarDate(2000, 12, 10)} />;
}
```

## Guidelines

### When to use it

- Typing a known date: a birthday, an expiry date.

### Use something else when

- [date-picker](https://design.senvenli.com/docs/components/date-picker.md): People need to see a calendar.

## Accessibility

Keyboard:

- Arrow up / down: Changes the focused part.

Built in:

- Required fields show "Fill in this field."; a partly typed date says what is missing.

You provide:

- A visible label.

## API reference

### DateField

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| label | `React.ReactNode` |  | yes | Always given; the label sits above the field and names its segments. |
| description | `React.ReactNode` |  | no |  |
| errorMessage | `React.ReactNode` |  | no | What happened and what to do; shown when the field is invalid. |
| isRequired | `boolean` |  | no |  |
| requiredValidation | `RequiredValidation` |  | no | Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract. |
| isOptional | `boolean` |  | no | Shows "(optional)" when most of the form is required. |
| isDisabled | `boolean` |  | no |  |
| isReadOnly | `boolean` |  | no |  |
| isInvalid | `boolean` |  | no | Marks the field invalid from outside (a server error); `errorMessage` says why. |
| id | `string` |  | no | The id of the field's first typed segment (day, or the locale's first part), the element that takes focus : `document.getElementById(id).focus()` puts the user in the field, as a focus-on-error does. The field's group gets an id of its own. Left out, the DOM is as before. |
| name | `string` |  | no | The form field name; the value is submitted as an ISO string. |
| autoFocus | `boolean` |  | no |  |
| onBlur | `(event: FocusEvent<Element, Element>) => void` |  | no |  |
| value | `CalendarDate` |  | no | A calendar date, no time zone. With `hideYear` its year is 2000 (a leap year, so 29 February exists; see `hideYear`); with `granularity="month"` it is the month's first day. While the user leaves a date typed in part or impossible ("31.aa.2026", "31.11.2026"), the field reports `onChange(null)` and keeps the typed parts on screen, so setting `null` changes nothing: the value already is null. To clear the field (an app's own "Temizle" or form reset), give it a new `key` along with the value: React remounts it empty, or at the value given. |
| defaultValue | `CalendarDate` |  | no |  |
| onChange | `(value: CalendarDate \| null) => void` |  | no |  |
| granularity | `"day" \| "month"` | `"day"` | no | `day` types day, month and year; `month` types month and year (a card's expiry) and the day is 1. |
| hideYear | `boolean` |  | no | Day and month only: a yearly date (a campaign day, a birthday reminder). The value is that day in the Gregorian year 2000, a leap year, so 29 February exists, whatever calendar the locale writes dates in: - A calendar with the Gregorian months (the Buddhist one of th-TH, ROC, Japanese): the day and month are typed as the locale writes them, and the hidden year is 2000 as that calendar counts it (2543, Minguo 89, Heisei 12), its era hidden with it. - A calendar with months of its own (Hebrew, Islamic, Persian, Indian, Ethiopic, Coptic, Chinese): one of its days falls on another Gregorian day every year, so no month–day of it is a yearly date the value can hold. The field types the Gregorian day and month instead, in the locale's language and digits. Give `value` and `defaultValue` in 2000 (`new CalendarDate(2000, month, day)`). The field never changes the year it is given: a value in another year keeps it, an edit reports in it, and the day is judged in it, so 29 February typed over a 2023 value says "February has 28 days." and reports null. |
| minValue | `CalendarDate` |  | no |  |
| maxValue | `CalendarDate` |  | no |  |
| validate | `(value: CalendarDate \| null) => string \| true \| string[] \| null \| undefined` |  | no | Your own check; return the message to show, or nothing when the date is fine. |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-radius-small`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

- [date-picker](https://design.senvenli.com/docs/components/date-picker.md)
- [time-field](https://design.senvenli.com/docs/components/time-field.md)
