Date picker
Choose a date from a familiar Material calendar.
Installation
pnpm dlx shadcn@latest add https://react-toolbox.io/r/date-picker.jsonNew here? Set up your project first. Styles, fonts, and required components are included.
Usage
Values are Date objects, bounded by minDate and maxDate. In the calendar, arrow keys move by day or week, Home/End move within the week, and PageUp/PageDown move by month (hold Shift for years).
Composition
CalendarSelection supports single, multiple and range values, multiple months, week numbers, unavailable-day predicates and clearing. Keyboard focus moves independently from selection.
| Week | M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|---|
| 40 | 1 | 2 | 3 | 4 | |||
| 41 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 42 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 43 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 44 | 26 | 27 | 28 | 29 | 30 | 31 |
| Week | M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|---|
| 44 | 1 | ||||||
| 45 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 46 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 47 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 48 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 49 | 30 |
Choose a visit range. Sundays are unavailable.
Show composition code
'use client';
import { useState } from 'react';
import { CalendarSelection, type DateRange } from '@/components/ui/material/date-picker';
export default function CalendarComposition() {
const [range, setRange] = useState<DateRange>({ from: undefined, to: undefined });
return (
<div>
<CalendarSelection
mode="range"
value={range}
onValueChange={setRange}
defaultMonth={new Date(2026, 9, 1)}
numberOfMonths={2}
showWeekNumbers
clearable
isDateUnavailable={(date) => date.getDay() === 0}
excludeUnavailable
/>
<p role="status" className="mt-4 text-toolbox-body">
{range.from
? `${range.from.toLocaleDateString()}${range.to ? ` – ${range.to.toLocaleDateString()}` : ' – choose an end date'}`
: 'Choose a visit range. Sundays are unavailable.'}
</p>
</div>
);
}
State and callbacks
- Use
value/onChange, ordefaultValuefor internal state and form reset. The dialog edits a draft until confirmation;autoOkconfirms a day selection immediately. - Visibility is internal by default. Use
defaultOpento initialize it oropen/onOpenChangeto control it. When controlled, updateopenfromonOpenChange;onDismissreports dismissal.
API reference
Key props and defaults. Full types and inline documentation are included with the source in material/date-picker.
DatePicker
| Property | Type | Default |
|---|---|---|
autoOk | boolean | — |
clearable | booleanShow a clear action. Controlled consumers clear by setting value to null. | — |
defaultOpen | boolean | — |
defaultValue | Date | — |
disabledDates | readonly Date[] | — |
endYear | number | — |
labels | Partial<DatePickerLabels> | — |
layout | 'portrait' | 'landscape' | 'responsive'Preserve portrait, force landscape, or adapt to wide landscape viewports. | — |
locale | DatePickerLocale | 'en' |
maxDate | Date | — |
minDate | Date | — |
onChange | (date: Date, event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void | — |
onOpenChange | (open: boolean) => void | — |
open | boolean | — |
readOnly | booleanKeep the value focusable and submitted while preventing edits and validation. | — |
startYear | number | — |
value | Date | null | — |
Material guidelines
- Use a calendar when the relationship between days helps someone choose a date. Distinguish today from the selected day.
- Keep selection provisional until confirmation, with clear Cancel and OK actions. Disable unavailable dates consistently.