DatePicker
An input field with a dd.MM.yyyy mask and a calendar popover. Controlled and uncontrolled modes.
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
<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.
<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.
<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
<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 rightClearing
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.
<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
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
| Prop | Type | Default | Description |
|---|---|---|---|
value | Date | — | Controlled value |
defaultValue | Date | — | Uncontrolled initial value |
onChange | (date: Date | undefined) => void | — | Callback on change |
label | string | — | Floating label |
placeholder | string | from format | Placeholder |
locale | Locale (date-fns) | ru | Locale |
dateFormat | string | 'dd.MM.yyyy' | Date format |
fromDate | Date | — | Minimum allowed |
toDate | Date | — | Maximum allowed |
disabledDates | Matcher | Matcher[] | — | Blocked dates |
showTime | boolean | { format: 'HH:mm' | 'HH:mm:ss' } | — | Enable time selection |
timePickerType | 'input' | 'drum' | 'input' | Time selection appearance |
noCalendar | boolean | false | Input only, no popover |
size | 's' | 'm' | 'l' | 'm' | Size |
disabled | boolean | false | Disabled |
failed | boolean | false | Error state |
loading | boolean | false | Loading |
icon | ReactNode | false | calendar | Icon |
iconPosition | 'start' | 'end' | 'end' | Icon position |
clearable | boolean | false | Clear button while the field is filled |
clearIcon | ReactNode | cross | Custom clear icon |
renderInput | (props) => ReactNode | — | Replace <input> |
customTrigger | (value, onClick) => ReactNode | — | Replace the entire trigger |
className | string | — | CSS class on the root |