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

`data-ui="date-range-picker"` · Start and end dates with a calendar popover.

## Import

```tsx
import { DateRangePicker, DateRangePickerDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

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

export default function DateRangePickerBasic() {
  return (
    <Field>
      <FieldLabel>Reporting period</FieldLabel>
      <DateRangePicker endName="periodEnd" startName="periodStart" />
      <FieldDescription>Type both dates or choose them from the calendar.</FieldDescription>
    </Field>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |
| `control` | div | yes |
| `trigger` | button | yes |
| `start` | div | yes |
| `separator` | span | yes |
| `end` | div | yes |
| `clear` | button | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `DateRange \| null` | — | DateRangePicker | The run held, either end of which may be null. Present means the consumer owns it. |
| `defaultValue` | `DateRange \| null` | null | DateRangePicker | What it starts from, and returns to on a form reset. Read once. |
| `position` | `'start' \| 'end'` | — | DateRangePicker | The end the next press writes. Present means the consumer owns it. |
| `defaultPosition` | `'start' \| 'end'` | start | DateRangePicker | The end it starts on. |
| `count` | `'days' \| 'nights'` | days | DateRangePicker | What the length counts. |
| `minLength` | `number` | — | DateRangePicker | The shortest run, in the unit count names. |
| `maxLength` | `number` | — | DateRangePicker | The longest run, in the unit count names. |
| `contiguous` | `boolean` | true | DateRangePicker | Whether a run may cross an unavailable day. |
| `min` | `PlainDate` | — | DateRangePicker | The earliest accepted date. |
| `max` | `PlainDate` | — | DateRangePicker | The latest accepted date. |
| `isDateUnavailable` | `(date: PlainDate) => boolean` | — | DateRangePicker | Refuses particular dates. |
| `presets` | `readonly PickerPreset<DateRange>[]` | — | DateRangePicker | The consumer’s own shortcuts. |
| `confirm` | `boolean` | true | DateRangePicker | Whether the panel keeps a draft until Apply. |
| `months` | `number` | 2 | DateRangePicker | How many months the panel shows. One below 760 pixels. |
| `weekNumbers` | `boolean` | false | DateRangePicker | Draws the ISO week number, as a press that chooses the week. |
| `fixedWeeks` | `boolean` | false | DateRangePicker | Six rows whatever the months need. |
| `firstDayOfWeek` | `number` | the locale’s | DateRangePicker | 0 is Sunday. |
| `yearPivot` | `number` | — | DateRangePicker | How a two-digit typed year resolves. |
| `calendar` | `'gregory'` | gregory | DateRangePicker | The calendar system. |
| `startName` | `string` | — | DateRangePicker | The name a form posts the start under. |
| `endName` | `string` | — | DateRangePicker | The name a form posts the end under. |
| `invalid` | `boolean` | — | DateRangePicker | Stated by the consumer; a run that fails a rule is invalid without it. |
| `open` | `boolean` | — | DateRangePicker | Whether the panel is showing. Present means the consumer owns it. |
| `defaultOpen` | `boolean` | false | DateRangePicker | Whether it starts open when nobody else says. Read once. |
| `placement` | `'bottom-start' \| 'bottom' \| 'bottom-end' \| 'top-start' \| 'top' \| 'top-end'` | bottom-start | DateRangePicker | Where the panel opens, before the positioner has read the room. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | DateRangePicker | The height of the control. The field around it answers when the picker does not. |
| `variant` | `'outline' \| 'subtle' \| 'plain'` | outline | DateRangePicker | How the control draws its frame. |
| `locale` | `string` | the language in force | DateRangePicker | BCP 47. Writes the field, the panel and the trigger’s name. |
| `timeZone` | `string` | the runtime’s | DateRangePicker | Which zone answers "what is now". |
| `today` | `PlainDate` | the clock’s | DateRangePicker | The day it is: the mark of today, and the month an empty panel opens on. |
| `disabled` | `boolean` | — | DateRangePicker | Answers no key and no press. |
| `readOnly` | `boolean` | — | DateRangePicker | Readable and not changeable. |
| `required` | `boolean` | — | DateRangePicker | The form needs a value. |
| `clearable` | `boolean` | false | DateRangePicker | Draws a clear on the control and in the panel, unless required. |
| `messages` | `Partial<DateRangePickerMessages>` | — | DateRangePicker | Words laid over the language in force: the trigger’s names, the two ends, what is said of a refused run, and the phrases that count it. |
| `DateRangePickerDefaultsProvider` | `component` | — | application | Sets calendar, confirm, count, months, placement, size, timeZone, today and variant once. |
| `footer` | `ReactNode` | the limits | DateRangePicker | What the footer says when nothing is wrong. |
| `render` | `(props: DateRangePickerRootProps) => ReactNode` | — | DateRangePicker | Substitutes the element the root renders. |
| `ref` | `Ref<DateRangePickerHandle>` | — | DateRangePicker | focus(), open() and close(). |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: DateRange \| null, request: ChangeRequest<DateRange \| null>)` | Before the value moves, and cancellable: from a key in a field, from Apply, from Clear. |
| `onOpenChange` | `(open: boolean, request: ChangeRequest<boolean>)` | Before the panel opens or closes, with the reason. |
| `onPositionChange` | `(position: DateRangePickerPosition, request: ChangeRequest<DateRangePickerPosition>)` | Before the end being edited moves. |

## 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` |
| `count` | `days`, `nights` | `days` |
| `position` | `start`, `end` | — |
| `calendar` | `gregory` | `gregory` |
| `confirm` | `on`, `off` | true |

## 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 leaves focus in the field, so the segments keep every key they had.
- The length between the two halves is a status region, so a reader hears "4 nights" on every arrow as much as they see it on every hover.
- The half being edited is a tint and a line, so it is told without color.

## Tokens

`--slotted-border-subtle`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-gap-lg`, `--slotted-control-gap-md`, `--slotted-control-gap-sm`, `--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-invalid-edge-width`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-shadow-focus-geometry`, `--slotted-control-surface`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-date-range-picker-action-active-background`, `--slotted-date-range-picker-action-color`, `--slotted-date-range-picker-action-hover-background`, `--slotted-date-range-picker-action-size`, `--slotted-date-range-picker-background`, `--slotted-date-range-picker-border-color`, `--slotted-date-range-picker-color`, `--slotted-date-range-picker-current-color`, `--slotted-date-range-picker-current-size`, `--slotted-date-range-picker-disabled-background`, `--slotted-date-range-picker-disabled-border-color`, `--slotted-date-range-picker-disabled-color`, `--slotted-date-range-picker-hover-border-color`, `--slotted-date-range-picker-invalid-border-color`, `--slotted-date-range-picker-invalid-edge-width`, `--slotted-date-range-picker-invalid-focus-ring-color`, `--slotted-date-range-picker-plain-hover-background`, `--slotted-date-range-picker-radius`, `--slotted-date-range-picker-readonly-background`, `--slotted-date-range-picker-separator-color`, `--slotted-date-range-picker-shadow`, `--slotted-date-range-picker-subtle-background`, `--slotted-date-range-picker-subtle-border-color`, `--slotted-date-range-picker-subtle-hover-background`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-focus-ring-color`, `--slotted-focus-ring-color-invalid`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-radius-none`, `--slotted-radius-xs`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-surface-sunken`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-border`, `--slotted-tone-accent-solid`, `--slotted-tone-danger-border`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`

## Examples

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