# Date picker

A date field with a calendar popover, Today and Clear actions, markers and unavailable days.

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

## Example: A date with a calendar

Type the date, or open the calendar to browse.

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

export default function Example() {
  // `timeZone` decides which day "Today" is: the warehouse's zone, not the visitor's device.
  return <DatePicker label="Delivery date" defaultValue={new CalendarDate(2026, 3, 18)} timeZone="America/New_York" />;
}
```

## Examples

### Unavailable days and markers

Closed days stay visible and say why; a dot marks days worth a look.

```tsx
import { CalendarDate, getDayOfWeek } from "@internationalized/date";
import { DatePicker } from "@senvenli/react/date";

// 0 is Sunday in en-US.
const isWeekend = (date: CalendarDate) => [0, 6].includes(getDayOfWeek(date, "en-US"));
const isFull = (date: CalendarDate) => date.month === 3 && [12, 20, 24].includes(date.day);

export default function Example() {
  return (
    <DatePicker
      label="Installation day"
      description="Weekdays only."
      defaultValue={new CalendarDate(2026, 3, 18)}
      timeZone="America/New_York"
      isDateUnavailable={(date) => isWeekend(date) || isFull(date)}
      unavailableReason={(date) => (isFull(date) ? "Fully booked" : isWeekend(date) ? "Closed" : undefined)}
      // `true` draws a dot; a phrase is also read by screen readers.
      getDateMarkers={(date) => (date.month === 3 && date.day === 19 ? "Last slot" : undefined)}
    />
  );
}
```

### With a range

Days outside `minValue` and `maxValue` cannot be picked or typed.

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

export default function Example() {
  return (
    <DatePicker
      label="Return by"
      description="Returns are accepted for 30 days after delivery."
      defaultValue={new CalendarDate(2026, 3, 25)}
      minValue={new CalendarDate(2026, 3, 18)}
      maxValue={new CalendarDate(2026, 4, 17)}
      timeZone="America/New_York"
    />
  );
}
```

### A month

For a report period: the popover is a grid of months.

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

export default function Example() {
  return (
    <DatePicker
      label="Report month"
      granularity="month"
      defaultValue={new CalendarDate(2026, 3, 1)}
      maxValue={new CalendarDate(2026, 3, 1)}
      timeZone="America/New_York"
    />
  );
}
```

### In Spanish

The locale names the months and days and orders the date; the label is yours.

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

// Month and weekday names, the date order and the first day of the week come from the locale. The label is the
// app's own words; the library's few strings stay English until you register Spanish ones.
export default function Example() {
  return (
    <DesignSystemProvider locale="es-ES">
      <DatePicker label="Fecha de entrega" defaultValue={new CalendarDate(2026, 3, 18)} timeZone="Europe/Madrid" />
    </DesignSystemProvider>
  );
}
```

### In Arabic, right to left

`dir="rtl"` mirrors the field and the calendar; digits follow the locale.

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

// Right to left: the page (here a wrapper) sets dir="rtl". The field and the calendar mirror, the arrows point the
// reading way, and the digits follow the locale (ar-EG uses Arabic-Indic digits; ar-AE keeps Latin ones).
export default function Example() {
  return (
    <div dir="rtl" lang="ar">
      <DesignSystemProvider locale="ar-EG">
        <DatePicker label="تاريخ التسليم" defaultValue={new CalendarDate(2026, 3, 18)} timeZone="Africa/Cairo" />
      </DesignSystemProvider>
    </div>
  );
}
```

### A range: A period

Start and end in one control over one calendar.

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

export default function Example() {
  return (
    <DatePicker selectionMode="range"
      label="Report period"
      defaultValue={{ start: new CalendarDate(2026, 3, 2), end: new CalendarDate(2026, 3, 18) }}
      timeZone="America/New_York"
    />
  );
}
```

### A range: With times

`granularity="hour"` adds a start and an end time.

```tsx
import { CalendarDateTime } from "@internationalized/date";
import { DatePicker } from "@senvenli/react/date";

export default function Example() {
  return (
    <DatePicker selectionMode="range"
      label="Maintenance window"
      description="Times are in the data center's zone."
      granularity="hour"
      defaultValue={{ start: new CalendarDateTime(2026, 3, 18, 22, 0), end: new CalendarDateTime(2026, 3, 19, 2, 30) }}
      timeZone="America/New_York"
    />
  );
}
```

### A range: Named halves and a total

Your own labels for the two halves, and a figure beside the day count under the calendar.

```tsx
import { useState } from "react";
import { CalendarDate } from "@internationalized/date";
import { DatePicker, type DateRangePickerValue } from "@senvenli/react/date";

const DAILY_BUDGET = 120;
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

export default function Example() {
  // The value is null while a half is empty or typed in part.
  const [range, setRange] = useState<DateRangePickerValue | null>({ start: new CalendarDate(2026, 3, 18), end: new CalendarDate(2026, 3, 25) });
  const days = range ? range.end.compare(range.start) : 0;
  return (
    <DatePicker selectionMode="range"
      label="Campaign dates"
      startLabel="First day"
      endLabel="Last day"
      value={range}
      onChange={setRange}
      minValue={new CalendarDate(2026, 3, 18)}
      timeZone="America/New_York"
      footer={days > 0 ? usd.format(days * DAILY_BUDGET) : undefined}
    />
  );
}
```

## Guidelines

### When to use it

- Picking a date where seeing the month helps.
- Picking a period: a stay, a trip, a report range.

### Use something else when

- [date-field](https://design.senvenli.com/docs/components/date-field.md): People type a known date, such as a birth date, and a calendar adds nothing.
- [calendar](https://design.senvenli.com/docs/components/calendar.md): The month grid stays visible on the page.

## Accessibility

Keyboard:

- Alt + Arrow down: Opens the calendar.

Built in:

- Unavailable days explain why.
- Required fields show "Fill in this field."; a partly typed date says what is missing.
- Both halves are labelled ("Start", "End") and typed independently.
- The range may not cross an unavailable day unless allowed.

You provide:

- A visible label.
- A label for the range.

## API reference

### DatePicker

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| defaultValue | `CalendarDate \| DateRangePickerValue` |  | no |  |
| autoFocus | `boolean` |  | no |  |
| 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. |
| onBlur | `(event: FocusEvent<Element, Element>) => void` |  | no |  |
| onChange | `(value: CalendarDate \| null) => void \| (value: DateRangePickerValue \| null) => void` |  | no |  |
| isDisabled | `boolean` |  | no |  |
| name | `string` |  | no | The form field name; the value is submitted as an ISO string. |
| 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. |
| isReadOnly | `boolean` |  | no |  |
| isInvalid | `boolean` |  | no | Marks the field invalid from outside (a server error); `errorMessage` says why. |
| minValue | `CalendarDate \| DateValue` |  | no |  |
| maxValue | `CalendarDate \| DateValue` |  | no |  |
| validate | `(value: CalendarDate \| null) => string \| true \| string[] \| null \| undefined \| (value: Span<DateValue> \| null) => string \| true \| string[] \| null \| undefined` |  | no | Your own check; return the message to show, or nothing when the date is fine. |
| value | `CalendarDate \| DateRangePickerValue` |  | no | A calendar date, no time zone; with `granularity="month"` 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. |
| isDateUnavailable | `(date: CalendarDate) => boolean` |  | no |  |
| unavailableReason | `(date: CalendarDate) => string \| undefined` |  | no |  |
| getDateMarkers | `(date: CalendarDate) => DateMarker \| undefined` |  | no |  |
| firstDayOfWeek | `FirstDayOfWeek` |  | no |  |
| timeZone | `string` |  | no | "Today" in the calendar and the Today action: the location's zone; the device's by default. |
| shouldCloseOnSelect | `boolean` |  | no | Close the calendar once a day is picked (default). |
| granularity | `"day" \| "month" \| "day" \| "hour"` |  | no | `month`: a year and a month, for a report or history range. The field types month and year (as DateField `granularity="month"`), the value is that month's first day, and the popover is a grid of the twelve months under a year stepper, with "This month" and "Clear"; `minValue` and `maxValue` count by month. The day-only props (unavailable days, markers, first day of the week) do not apply. Default `day`. |
| selectionMode | `"single" \| "range"` |  | no | `single` (default): one date (and time with `granularity="hour"`). |
| allowsNonContiguousRanges | `boolean` |  | no |  |
| startLabel | `string` |  | no | Overline labels of the two halves; "Start" and "End" by default. |
| endLabel | `string` |  | no |  |
| footer | `React.ReactNode` |  | no | Right of the duration under the calendar: the price total (`metric-small`). |
| startName | `string` |  | no | Form field names for the two halves (ISO strings). |
| endName | `string` |  | no |  |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-brand-bold-hovered`, `--ds-background-neutral-subtle-hovered`, `--ds-background-selected`, `--ds-background-selected-hovered`, `--ds-border`, `--ds-border-focused`, `--ds-border-selected`, `--ds-icon`, `--ds-icon-brand`, `--ds-radius-control-medium`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-small`, `--ds-shadow-raised`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-space-050`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-400`, `--ds-surface-raised`, `--ds-text`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

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