<!-- index: /slotted/llms.txt -->
# date-picker

`data-ui="date-picker"` · Date field with a calendar popover.

## Import

```tsx
import { DatePicker, DatePickerDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { DatePicker } from '@slotted/react/date-picker';
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';

export default function DatePickerBasic() {
  return (
    <Field>
      <FieldLabel>Requested delivery date</FieldLabel>
      <DatePicker name="deliveryDate" />
      <FieldDescription>Type the date or choose it from the calendar.</FieldDescription>
    </Field>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |
| `control` | div | yes |
| `trigger` | button | yes |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `PlainDate \| DateRange \| PlainDate[] \| null` | — | DatePicker | The value held, which depends on selectionMode. Present means the consumer owns it. Under granularity="month", a PlainYearMonth. |
| `defaultValue` | `PlainDate \| DateRange \| PlainDate[] \| null` | null | DatePicker | What it starts from, and returns to on a form reset. Read once. |
| `granularity` | `'day' \| 'month'` | day | DatePicker | What a choice is. |
| `selectionMode` | `'single' \| 'range' \| 'multiple'` | single | DatePicker | How many dates the value holds. |
| `months` | `number` | 1 | DatePicker | How many months the panel shows. One below 760 pixels. |
| `defaultView` | `'day' \| 'month' \| 'year'` | day | DatePicker | The view the calendar opens on. |
| `min` | `PlainDate` | — | DatePicker | The earliest accepted date. |
| `max` | `PlainDate` | — | DatePicker | The latest accepted date. |
| `isDateUnavailable` | `(date: PlainDate) => boolean` | — | DatePicker | Refuses particular dates. |
| `presets` | `readonly PickerPreset<CalendarValue>[]` | — | DatePicker | The consumer’s own shortcuts, after Today. Without any, the panel is the month alone. |
| `confirm` | `boolean` | off for one date | DatePicker | Whether the panel keeps a draft until Apply. |
| `weekNumbers` | `boolean` | false | DatePicker | Draws the ISO week number; in a run, a press on it chooses the week. |
| `fixedWeeks` | `boolean` | true | DatePicker | Six rows whatever the month needs, with one month. |
| `firstDayOfWeek` | `number` | the locale’s | DatePicker | 0 is Sunday. |
| `yearPivot` | `number` | — | DatePicker | How a two-digit typed year resolves. |
| `calendar` | `'gregory'` | gregory | DatePicker | The calendar system. |
| `name` | `string` | — | DatePicker | The name a form posts the date under. |
| `invalid` | `boolean` | — | DatePicker | Stated by the consumer; a refused date is invalid without it. |
| `open` | `boolean` | — | DatePicker | Whether the panel is showing. Present means the consumer owns it. |
| `defaultOpen` | `boolean` | false | DatePicker | Whether it starts open when nobody else says. Read once. |
| `placement` | `'bottom-start' \| 'bottom' \| 'bottom-end' \| 'top-start' \| 'top' \| 'top-end'` | bottom-start | DatePicker | Where the panel opens, before the positioner has read the room. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | DatePicker | The height of the control. The field around it answers when the picker does not. |
| `variant` | `'outline' \| 'subtle' \| 'plain'` | outline | DatePicker | How the control draws its frame. |
| `locale` | `string` | the language in force | DatePicker | BCP 47. Writes the field, the panel and the trigger’s name. |
| `timeZone` | `string` | the runtime’s | DatePicker | Which zone answers "what is now". |
| `today` | `PlainDate` | the clock’s | DatePicker | The day it is: the mark of today, Today, and the month an empty panel opens on. |
| `disabled` | `boolean` | — | DatePicker | Answers no key and no press. |
| `readOnly` | `boolean` | — | DatePicker | Readable and not changeable. |
| `required` | `boolean` | — | DatePicker | The form needs a value. |
| `clearable` | `boolean` | false | DatePicker | Draws a clear on the control and in the panel, unless required. |
| `messages` | `Partial<DatePickerMessages>` | — | DatePicker | Words laid over the language in force: the trigger’s two names, and what is said of a refused date. |
| `DatePickerDefaultsProvider` | `component` | — | application | Sets calendar, confirm, placement, size, timeZone, today and variant once. |
| `footer` | `ReactNode` | the page keys | DatePicker | What the footer says when nothing is wrong. |
| `render` | `(props: DatePickerRootProps) => ReactNode` | — | DatePicker | Substitutes the element the root renders. |
| `ref` | `Ref<DatePickerHandle>` | — | DatePicker | focus(), open() and close(). |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: CalendarValue, request: ChangeRequest<CalendarValue>)` | Before the value moves, and cancellable: from a key in the field, from a press, from Apply, from Clear. |
| `onOpenChange` | `(open: boolean, request: ChangeRequest<boolean>)` | Before the panel opens or closes, with the reason. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `outline`, `subtle`, `plain` | `outline` |
| `placement` | `bottom-start`, `bottom`, `bottom-end`, `top-start`, `top`, `top-end` | `bottom-start` |
| `calendar` | `gregory` | `gregory` |
| `confirm` | `on`, `off` | — |

## Rules

- The trigger says aria-haspopup="dialog" and its name carries the value written, which is where focus returns when the panel closes.
- The panel is a dialog with its Tab wrapped, and each grid inside it is one stop.
- Escape discards the draft and returns focus to the trigger. Ctrl+Enter applies from anywhere in the panel.
- The footer’s hint is a status region, so the reason Apply is off is spoken as well as drawn.
- Alt+ArrowDown opens the panel and takes focus to the chosen day.
- Escape walks the calendar’s view down before it closes the panel, so a reader in the years is not thrown out of it.

## Tokens

`--slotted-control-border-width`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-radius`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-date-picker-invalid-focus-ring-color`, `--slotted-date-picker-radius`, `--slotted-date-picker-trigger-active-background`, `--slotted-date-picker-trigger-color`, `--slotted-date-picker-trigger-hover-background`, `--slotted-date-picker-trigger-size`, `--slotted-disabled-foreground`, `--slotted-focus-ring-color`, `--slotted-focus-ring-color-invalid`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-space-2`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text-muted`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`

## Examples

See [date-picker.examples.md](./date-picker.examples.md).
