# Date Input

A date people know by heart, typed one part at a time: dates of birth, incorporation dates, dates off a document. No calendar, because paging back decades is slower than typing. For a date near today, like a due date or appointment, use Date Picker.

- Beta: ready to use; its API can still change in a minor release.
- Category: Form fields

```tsx
import { DateInput, Field } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for dates people know by heart or read off a document, like a client's date of birth, a company's incorporation date or the date on a will. Typing is faster than paging back decades.
- Do: Put it in a `Field` with a label. Outside a field, like in a table filter, name it with `aria-label`.
- Do: Treat the value as missing until every part is filled. It stays null until then, and then it is an ISO date like `1984-02-03`.
- Do: Set `max` to today for a date that can't be in the future, like a date of birth, so a future date shows as invalid and its form won't submit.
- Don't: Use it for a due date, an appointment or a settlement. Use `DatePicker`, where the week around the date helps.

## Keyboard

| Keys | What they do |
| --- | --- |
| Typing | Fills each segment and moves on to the next. |
| ArrowUp, ArrowDown | Step a segment, wrapping around. |
| ArrowLeft, ArrowRight | Move between segments. |
| Page Up, Page Down | Take bigger steps. |
| Home, End | Go to a segment's first and last values. |
| Backspace | Empties a segment, then moves back. |
| Tab | Moves through the segments, then out. |
| Enter | Submits the form with what was typed. |

## Related

- [Date Picker](./date-picker.md)
- [Calendar](./calendar.md)
- [Field](./field.md)

## Examples

What the examples import:

```tsx
import { Fragment } from "react";
import { DateInput, Field } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const sizes = ["xs", "sm", "md", "lg"] as const;
```

### Date of birth

Click the day and type 03021984: each part moves on as it fills. Arrow keys step a part, and a whole date can be pasted. max stops a birthday in the future.

```tsx
<div className="w-48">
  <Field label="Date of birth" hint="As on their ID.">
    <DateInput locale="en-AU" max="2026-11-22" required />
  </Field>
</div>
```

### Sizes

```tsx
<div className="grid w-56 grid-cols-[auto_1fr] items-center gap-x-4 gap-y-3">
  {sizes.map(size => (
    <Fragment key={size}>
      <span className="text-small text-neutral-text-muted">{size}</span>
      <DateInput
        size={size}
        aria-label={`Date of birth, ${size}`}
        defaultValue="1984-02-03"
        locale="en-AU"
      />
    </Fragment>
  ))}
</div>
```

### States

```tsx
<div className="grid w-full max-w-2xl grid-cols-3 gap-x-6 gap-y-6">
  <Field label="Error" error="Please enter a valid date">
    <DateInput defaultValue="1984-02-03" locale="en-AU" />
  </Field>
  <Field label="Read-only">
    <DateInput defaultValue="1984-02-03" locale="en-AU" readOnly />
  </Field>
  {/* A disabled Field dims its label, and axe checks a group's label
      for contrast where it skips a disabled input's; a caption
      stands in for it here. */}
  <div className="flex flex-col gap-1.5">
    <span className="text-small text-neutral-text-muted">Disabled</span>
    <DateInput
      aria-label="Disabled date"
      defaultValue="1984-02-03"
      locale="en-AU"
      disabled
    />
  </div>
</div>
```

## Props

Also takes ui-sdk's Date Input options: value, defaultValue, onValueChange, min, max, unavailable, locale, granularity, name, required, disabled and readOnly.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `TextSize` | `"md"` | xs 28, sm 32, md 36 (forms, the default), lg 40, as Input. |
| `aria-label` | `string` |  | Names the field outside a Field. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
