Date Picker
A date field with a calendar popup. Type a date or pick one, alone or as a range.
Usage
import {
DatePicker,
DatePickerContent,
DatePickerField,
DatePickerInput,
DatePickerTrigger,
} from 'nyctoui/date-picker'
<DatePicker defaultValue="2026-12-14">
<DatePickerField>
<DatePickerInput aria-label="Due date" />
<DatePickerTrigger />
</DatePickerField>
<DatePickerContent />
</DatePicker>The input reads dates in the locale’s order, ISO dates and month names, and formats the date once it is committed with Enter or on blur. Text that isn’t a date marks the field invalid and keeps the last good value. Either way the value is an ISO date string.
The popup is a Calendar: it takes the same options on the root, such as min, unavailable and minDays, and the same parts inside DatePickerContent. Without children it shows the navigation and the months.
Good for
- A due date on a task in a project tool.
- Check-in and check-out on a hotel or rental booking form.
- A report’s date range in an analytics dashboard, with presets like Last 7 days.
- An appointment date in a clinic’s booking flow.
Anatomy
<DatePicker>
<DatePickerField>
<DatePickerInput />
<DatePickerInput end />
<DatePickerClear />
<DatePickerTrigger />
</DatePickerField>
<DatePickerHint />
<DatePickerContent>
<DatePickerPresets>
<DatePickerPreset />
</DatePickerPresets>
<DatePickerCalendar>
<CalendarNav />
<CalendarMonths />
<CalendarFooter />
</DatePickerCalendar>
</DatePickerContent>
</DatePicker>Examples
Range
mode="range" takes an input for each end; the second has end. The popup stays open after the start and closes once the end is picked.
Booking
A stay of at least 3 nights with nightly prices, around booked nights, in two large months. DatePickerClear shows once there are dates to clear.
Presets
DatePickerPreset picks its value and closes the popup, and shows as selected while it matches. The app works out relative dates such as the last 7 days.
Hint and clear
The hint is read with the input. Its children function gets an example date in the locale’s format.
Button trigger
Where typing isn’t needed, put a Calendar in a Popover behind a button. Control open to close it once a date is picked.
Best practices
- Let people type the date as well as pick it; typing is faster when they already know it.
- Set
min,maxandunavailableto the dates that make sense, so wrong ones can’t be chosen. - Add
DatePickerPresetsfor ranges people pick again and again, such as Last 30 days or This quarter. - Add
DatePickerClearwhen the date is optional.
- Use a range picker when only one date is needed.
- Use a date picker for text that isn’t a calendar date, like a card’s expiry month.
- Hide the label unless the context makes the date’s purpose obvious.
API reference
DatePicker
Holds the value and the open state, and takes every Calendar option. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
modeOne date, or a range with an input for each end. | 'single' | 'range' | 'single' |
value / defaultValueThe selected date or range. | string | [string, string] | null | — |
onValueChangeCalled when a date is picked, typed and committed, cleared or set by a preset. | (value, details) => void | — |
calendarSizeDay size in the popup, as Calendar’s size. | 'md' | 'lg' | 'md' |
monthsHow many months the popup shows side by side. | number | 1 |
min / max / unavailableDates that can’t be picked. They are invalid when typed too. | string / DateMatchers | — |
minDays / maxDays / allowUnavailableRange limits, as on Calendar. | number / boolean | — |
open / defaultOpen / onOpenChangeThe popup’s open state. | boolean | — |
closeOnSelectCloses the popup once a date or a range’s end is picked. | boolean | true |
name / startName / endNameForm field names. The value submits as ISO dates. | string | — |
required / disabled / readOnlyAs on a native input. | boolean | false |
controllerDrives it from elsewhere. Create one with createDatePickerController(). | DatePickerController | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerField
The input box around the inputs and buttons; the popup lines up under it. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
sizeControl height; matches Input and Button. | 'sm' | 'md' | 'lg' | 'md' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerInput
Where a date is typed. Renders an <input>.
| Prop | Type | Default |
|---|---|---|
endHolds a range’s end. | boolean | false |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerTrigger
A ghost icon button that opens the popup, named by the chosen date. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerClear
Clears the value and focuses the input; hidden while empty. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
aria-labelThe accessible name of the button. | string | 'Clear date' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerHint
Describes the expected format. Renders a <span>.
| Prop | Type | Default |
|---|---|---|
childrenThe state has example, a date in the locale’s format. | ReactNode | (state) => ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerContent
The popup. Renders a <div> in the top layer.
| Prop | Type | Default |
|---|---|---|
sideWhich side of the field to open on. Flips when it would clip. | 'top' | 'right' | 'bottom' | 'left' | 'bottom' |
alignHow to line up with the field. | 'start' | 'center' | 'end' | 'start' |
anchorPositions against another element than the field. | Element | string | null | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerCalendar
Lays out the Calendar parts beside presets. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerPresets
A column of presets beside the calendar. Renders a <div> with the group role.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DatePickerPreset
Picks its value and closes the popup. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
valueThe date or range it picks. | string | [string, string] | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |