daterly

DatePicker

An input field with a dd.MM.yyyy mask and a calendar popover. Controlled and uncontrolled modes.

previewDatePicker
Date

Basic example

import { DatePicker } from 'daterly';

<DatePicker label="Date of birth" />;

Controlled

import { useState } from 'react'
import { DatePicker } from 'daterly'

const [date, setDate] = useState<Date | undefined>()

<DatePicker label="Date" value={date} onChange={setDate} />

If value is passed (even undefined), the component treats itself as controlled. Use defaultValue for uncontrolled mode.

With time selection

previewLive component · HH:mm
Date and time
<DatePicker label="Date and time" showTime={{ format: 'HH:mm' }} />

// or with seconds
<DatePicker label="Timestamp" showTime />

showTime={true} is equivalent to { format: 'HH:mm:ss' }.

TimePicker variants

The timePickerType prop controls how time selection looks in the popover. The default is 'input'.

'input' — compact numeric fields next to the OK button, on the same row as the calendar. A good fit when you need quick keyboard entry.

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

'drum' — vertical "drums" below the calendar, scrolled by click or wheel. A good fit for touch devices and scenarios where the time matters more than the date.

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

In both modes the popover doesn't close automatically — it closes via the OK button.

Restricting the range

<DatePicker
  label="Check-in date"
  fromDate={new Date()} // no earlier than today
  toDate={new Date(2027, 11, 31)} // no later than 31.12.2027
/>

The constraint applies to both the calendar and manual input: an out-of-range day can't be clicked, and a date typed or pasted into the field is flagged as invalid — the field gets aria-invalid and onChange fires with undefined.

Blocking arbitrary dates

disabledDates blocks any set of dates, contiguous or not. It accepts whatever react-day-picker's disabled accepts: a Date, an array, an interval, a day of the week, a predicate.

<DatePicker label="Visit date" disabledDates={[new Date(2027, 0, 1), new Date(2027, 0, 7)]} />

<DatePicker label="Weekdays only" disabledDates={{ dayOfWeek: [0, 6] }} />

<DatePicker label="January excluded" disabledDates={{ from: new Date(2027, 0, 1), to: new Date(2027, 0, 31) }} />

<DatePicker label="Even days only" disabledDates={(date) => date.getDate() % 2 !== 0} />

It combines with fromDate / toDate — the conditions add up. DateRangePicker takes the same prop and checks both ends of the range; a range that spans a blocked day is still allowed.

States

<DatePicker label="Error" failed />
<DatePicker label="Loading" loading />
<DatePicker label="Disabled" disabled />

failed draws a red border. loading replaces the icon with a spinner and blocks input. disabled blocks both the input and the popover.

Sizes

previewLive component · size=s
Small
previewLive component · size=l
Large
<DatePicker size="s" />
<DatePicker size="m" />  {/* default */}
<DatePicker size="l" />

Read more on the Sizes page.

Without the calendar

Just the masked input, no popover:

<DatePicker noCalendar label="Date (no calendar)" />

Icon

<DatePicker icon={false} />                    // hide
<DatePicker icon={<MyIcon />} />               // replace
<DatePicker iconPosition="start" />            // on the left instead of the right

Clearing

With clearable, a cross appears in the field as soon as it holds a value. Clicking it resets the date and calls onChange(undefined), leaving focus in the input.

previewLive component · clearable
Date
<DatePicker clearable label="Date" />

The cross takes the place of the trailing icon. With iconPosition="start" the calendar icon stays on the left and the cross sits on the right.

Replace the cross itself through clearIcon:

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

The prop is only read when clearable is set. The icon goes inside the button, so its click handler, aria-label and styles stay as they are.

Custom trigger

Replace the entire input with your own element:

<DatePicker
  customTrigger={(value, onClick) => (
    <button type="button" onClick={onClick}>
      {value || 'Pick a date'}
    </button>
  )}
/>

In this case there's no masked input — only a click on the trigger opens the popover.

Custom input

Keep the mask logic but swap out the <input> itself for a component from your UI kit:

import { Input } from 'antd';

<DatePicker
  renderInput={({ ref, className, ...props }) => (
    <Input ref={ref as any} {...props} />
  )}
/>;

All handlers (onChange, onKeyDown, onPaste, …) are already included in props.

Locale and format

previewLive component · locale=en-US · format=MM/dd/yyyy
Birthday
previewLive component · locale=de · format=dd.MM.yyyy
Geburtstag
import { enUS, de } from 'date-fns/locale'

<DatePicker locale={enUS} dateFormat="MM/dd/yyyy" label="Birthday" />
<DatePicker locale={de}   dateFormat="dd.MM.yyyy" label="Geburtstag" />

See the dedicated Locales and formats page.

Props

PropTypeDefaultDescription
valueDate—Controlled value
defaultValueDate—Uncontrolled initial value
onChange(date: Date | undefined) => void—Callback on change
labelstring—Floating label
placeholderstringfrom formatPlaceholder
localeLocale (date-fns)ruLocale
dateFormatstring'dd.MM.yyyy'Date format
fromDateDate—Minimum allowed
toDateDate—Maximum allowed
disabledDatesMatcher | Matcher[]—Blocked dates
showTimeboolean | { format: 'HH:mm' | 'HH:mm:ss' }—Enable time selection
timePickerType'input' | 'drum''input'Time selection appearance
noCalendarbooleanfalseInput only, no popover
size's' | 'm' | 'l''m'Size
disabledbooleanfalseDisabled
failedbooleanfalseError state
loadingbooleanfalseLoading
iconReactNode | falsecalendarIcon
iconPosition'start' | 'end''end'Icon position
clearablebooleanfalseClear button while the field is filled
clearIconReactNodecrossCustom clear icon
renderInput(props) => ReactNode—Replace <input>
customTrigger(value, onClick) => ReactNode—Replace the entire trigger
classNamestring—CSS class on the root

On this page