Molecules · Date range picker
Date range picker
A start and an end date in one field, an add-on to DatePicker. Type both, or open two months side by side: the first day you pick is the start, the band follows you to the second, which sets the end and closes the calendar. Put DatePresets in `aside` for one-click periods like Last 7 days. Installs DatePicker with it.
- Best for
- A booking, a report window, a leave request.
- Not for
- One day: DatePicker.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Default
Code
tsx
<div className="w-full max-w-sm"> <DateRangePicker label="Stay" /></div>With DatePresets beside the months
mmddyyyy
mmddyyyy
Pick a preset, or two days.
Code
tsx
<div className="w-full max-w-sm"> <FormField label="Report period" help="Pick a preset, or two days."> <DateRangePicker aside={<DatePresets />} /> </FormField></div>Controlled: the page holds the range
start: 2026-11-09, end: 2026-11-13
Code
tsx
function Controlled() { const [range, setRange] = useState<DateRange>({ start: '2026-11-09', end: '2026-11-13' }) return ( <div className="flex w-full max-w-sm flex-col gap-2"> <DateRangePicker label="Leave" value={range} onValueChange={setRange} /> <span className="font-mono text-xs text-[var(--color-text-secondary)]"> start: {range.start || '—'}, end: {range.end || '—'} </span> </div> )}<Controlled />Limits: November and December only
Code
tsx
<div className="w-full max-w-sm"> <DateRangePicker label="Rental" min="2026-11-01" max="2026-12-30" defaultValue={{ start: '2026-11-20', end: '2026-11-23' }} /></div>Anatomy
| Part | What it is |
|---|---|
| Field | A group named by the label, holding two segmented dates (Start date, End date) and the calendar button. A typed end before the start marks it invalid. |
| Calendar | Two months, stacked on narrow screens. The ends are solid accent squares, the days between a light accent band. |
| Hint | "Pick the first day." or "Pick the last day.", under the months, announced when it changes. |
| Aside | An optional column beside the months, for DatePresets. |
Props
- labelstring
- Names the field. Leave it out inside a FormField, which sets it from its own label. Outside one it is required, and `division-ds check` flags a missing one.
- value{ start: string; end: string }
- Controlled range. Each end is 'YYYY-MM-DD' or ''.
- defaultValue{ start: string; end: string }Default { start: '', end: '' }
- Starting range when the picker holds it itself.
- onValueChange(range: DateRange) => void
- Fires when either end changes. Days picked in the calendar always arrive in order.
- minstring
- Earliest date, 'YYYY-MM-DD'.
- maxstring
- Latest date, 'YYYY-MM-DD'.
- isDateDisabled(date: string) => boolean
- Days that cannot be picked.
- localestring
- Segment order, names and first day of the week. Defaults to the browser's.
- weekStartsOnnumber
- 0 Sunday to 6 Saturday. Defaults to the locale's.
- asideReactNode
- Beside the months, in the popover. DatePresets reads and sets the range by itself here.
- partLabels[string, string]Default ['Start date', 'End date']
- The names of the two dates.
- disabledbooleanDefault false
- Disables both dates and the button.
- invalidboolean
- Marks the field invalid. FormField sets it.
- requiredboolean
- Marks both dates required. FormField sets it.
- namestring
- Submits name-start and name-end with a form.
- idstring
- The field's id. FormField sets it.
- aria-describedbystring
- The ids of the help and error text. FormField sets it.
- classNamestring
- Combined with the field's classes.
- refRef<HTMLDivElement>
- The field's group element.
- useDateRangePicker()() => { value: DateRange; select: (range: DateRange) => void } | null
- Inside the popover: the range, and a way to set it and close. For your own aside content.
Keyboard
| Keys | Result |
|---|---|
| 0–9↑↓ | Types or steps the focused segment of either date. |
| ←→ | In the field: the next segment, across both dates. In the calendar: the day before or after, moving the band. |
| Page UpPage Down | A month earlier or later. With Shift, a year. |
| EnterSpace | Picks the start, then the end, which closes the calendar. |
| Esc | Closes the calendar. A start picked without an end stays as the start. |
Do and don't
Do
- Add DatePresets in aside when people mostly want the usual periods.
- Validate the length yourself if a range has a limit (a 30-day report), and say so in help text.
Don't
- Don't use two separate DatePickers for a start and an end: nobody sees the band.
- Don't reorder a typed range for the user; the field marks it invalid so they can see what they typed.