# Date Picker

A date near today, like a due date or settlement, typed in the locale's format or picked from the calendar the icon opens, in the same box and states as Input. Built on ui-sdk's Date Picker: a typed date commits on Enter or blur, and the value is an ISO date.

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

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

## Best practices

- Do: Use it for dates near today, like a due date, a settlement or a follow-up, where seeing the week around the date helps.
- Do: Use `DateRangePicker` with presets for reporting windows, like this month or the last 30 days, so the common range is one click.
- Do: Set `clearable` when the date is optional, so a lawyer can remove it without typing over it.
- Don't: Use it for a date of birth, an incorporation date or a date read off a document. Use `DateInput`: typing the date is faster than paging back decades.
- Don't: Put two date pickers side by side for a start and an end. Use `DateRangePicker`, which keeps the end after the start.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter | Makes a date typed in the page's format the value. |
| Enter, Space | On the calendar button, opens the calendar with focus on the selected date. |
| Arrow keys | Move by day and by week in the open calendar. |
| Escape | Closes the calendar and returns focus to its button. |

## Related

- [Date Input](./date-input.md)
- [Calendar](./calendar.md)
- [Time Picker](./time-picker.md)

## Examples

What the examples import:

```tsx
import { Fragment } from "react";
import { DatePicker, DateRangePicker, 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;
```

### In a field

Type 12/12/2026 or press the calendar. The locale decides the order: en-AU reads day first. For a date people know by heart, like a date of birth, use Date Input: no calendar to page back through.

```tsx
<div className="w-64">
  <Field label="Settlement date" hint="When the funds change hands.">
    <DatePicker locale="en-AU" required clearable />
  </Field>
</div>
```

### Sizes

```tsx
<div className="grid w-72 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>
      <DatePicker
        size={size}
        aria-label={`Settlement date, ${size}`}
        defaultValue="2026-12-12"
        locale="en-AU"
      />
    </Fragment>
  ))}
</div>
```

### States

```tsx
<div className="grid w-full max-w-2xl grid-cols-2 gap-x-6 gap-y-6">
  <Field label="Error" error="Please enter a valid date">
    <DatePicker defaultValue="2026-12-12" locale="en-AU" />
  </Field>
  <Field label="Read-only">
    <DatePicker defaultValue="2026-12-12" locale="en-AU" readOnly />
  </Field>
  <Field label="Disabled" disabled>
    <DatePicker defaultValue="2026-12-12" locale="en-AU" />
  </Field>
</div>
```

### Range

DateRangePicker: the start, a dash and the end in one field. Pick the start in the calendar, then the end; the band fills between them. The value is [start, end] and changes once both are set.

```tsx
<Field label="Settlement window" className="w-80">
  <DateRangePicker
    defaultValue={["2026-12-01", "2026-12-14"]}
    locale="en-AU"
    clearable
  />
</Field>
```

### Range with presets

presets lists ranges one press away beside the calendar; the matching one shows as selected.

```tsx
<Field label="Created" className="w-80">
  <DateRangePicker
    locale="en-AU"
    presets={[
      { label: "Last 7 days", value: ["2026-11-16", "2026-11-22"] },
      { label: "Last 30 days", value: ["2026-10-24", "2026-11-22"] },
      { label: "This month", value: ["2026-11-01", "2026-11-30"] },
      { label: "Last month", value: ["2026-10-01", "2026-10-31"] },
    ]}
  />
</Field>
```

## Props

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

### DatePicker

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `TextSize` | `"md"` | xs 28, sm 32, md 36 (forms, the default), lg 40, as Input. |
| `placeholder` | `string` |  | Shown while the field is empty. The locale's own pattern, like dd/mm/yyyy, when left out. |
| `clearable` | `boolean` | `false` | Shows a × that empties the field. |
| `aria-label` | `string` |  | Names the field outside a Field. |
| `id` | `string` |  | The control's id, for a label's htmlFor or aria-describedby. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DateRangePicker

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `DateRange \| null` |  | The range as [start, end] ISO dates, or null. Pass it to control the picker. |
| `defaultValue` | `DateRange \| null` |  | The range it starts with, as two ISO dates, when it controls itself. |
| `onValueChange` | `(value: DateRange \| null) => void` |  | Runs once both ends are set, or with null when cleared. |
| `presets` | `DateRangePreset[]` |  | Ranges one press away, listed beside the calendar, like "Last 7 days". |
| `size` | `TextSize` | `"md"` | xs 28, sm 32, md 36 (forms, the default), lg 40, as Input. |
| `placeholder` | `string` |  | Shown in each empty input. The locale's own pattern when left out. |
| `clearable` | `boolean` | `false` | Shows a × that empties the field. |
| `aria-label` | `string` |  | Names the range outside a Field: the inputs read "<label>, start" and "<label>, end". |
| `id` | `string` |  | The control's id, for a label's htmlFor or aria-describedby. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
