daterly

DateRangePicker

An input field for a date range. Mask dd.mm.yyyy — dd.mm.yyyy, a popover with two months, and a two-phase click in the calendar.

previewDateRangePicker
Range

Basic example

import { useState } from 'react'
import { DateRangePicker, type DateRange } from 'daterly'

const [range, setRange] = useState<DateRange | undefined>()

<DateRangePicker
  label="Stay period"
  value={range}
  onChange={setRange}
/>

Two-phase selection

The first click in the calendar sets the start of the range (the anchor). The second click confirms the end and closes the popover. As you move the mouse between clicks, the potential range is highlighted.

If you click a date earlier than the anchor, it automatically becomes the start, and the original anchor becomes the end.

Calendar layout

<DateRangePicker calendarLayout="horizontal" />   {/* by default */}
<DateRangePicker calendarLayout="vertical" />     {/* stacked */}

With time selection

previewLive component · HH:mm
Range (HH:mm)
<DateRangePicker
  label="Range down to the minute"
  showTime={{ format: 'HH:mm' }}
/>

Two time-selection fields appear below the calendar — one for the start and one for the end of the range. In this mode the popover does not close automatically; it is closed with the OK button.

TimePicker variants

The timePickerType prop controls the appearance of the time selection. The default is 'input'.

'input' — two compact numeric fields next to the OK button (Start / End). Convenient for keyboard input.

previewLive component · HH:mm · timePicker=input
TimePicker: input
<DateRangePicker showTime={{ format: 'HH:mm' }} timePickerType="input" />

'drum' — two "drums" below the calendar, scrolled by click or mouse wheel. Suited for touch devices.

previewLive component · HH:mm · timePicker=drum
TimePicker: drum
<DateRangePicker showTime={{ format: 'HH:mm' }} timePickerType="drum" />

Locale

previewLive component · locale=en-US · format=MM/dd/yyyy
Period
import { enUS } from 'date-fns/locale'

<DateRangePicker locale={enUS} dateFormat="MM/dd/yyyy" label="Period" />

Constraints

<DateRangePicker fromDate={new Date()} toDate={new Date(2027, 11, 31)} />

The constraint applies to both the calendar and manual input. Out-of-range days can't be clicked. A date typed or pasted into the field outside the range is flagged as invalid: the field gets aria-invalid and that end of the range reaches onChange as undefined.

Arbitrary dates are blocked through disabledDates — see DatePicker:

<DateRangePicker disabledDates={{ dayOfWeek: [0, 6] }} />

Both ends of the range are checked. A range that spans a blocked day is allowed, same as react-day-picker's calendar by default.

Clearing

previewLive component · clearable
Period
<DateRangePicker clearable label="Period" />

The cross appears as soon as the field holds a value — including when only the start date is picked. Clicking it resets both dates and calls onChange(undefined).

Use your own icon through clearIcon, same as on DatePicker:

<DateRangePicker clearable clearIcon={<MyCloseIcon />} />

All props

The same as DatePicker, plus:

PropTypeDefaultDescription
valueDateRange—{ from, to }
defaultValueDateRange—Initial range
onChange(range: DateRange | undefined) => void—Callback
calendarLayout'horizontal' | 'vertical''horizontal'Layout of the two months

DateRange is imported from the main entry point:

import type { DateRange } from 'daterly';

On this page