Date picker
A DatePicker is an inline calendar for one day, with an optional time. To pick a date from a text field, use Date input.
Usage#
import { DatePicker } from "@clawscale/react/datetime";<DatePicker defaultValue={new Date(2026, 7, 17)} onChange={(date) => setReleaseDate(date)} />Examples#
Basic#
Pass value and onChange to control the selection. Clicking the selected day again clears it and calls onChange with null. Set canClearSelection={false} to prevent that.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Tag } from "@clawscale/react";
import { DatePicker } from "@clawscale/react/datetime";
import { useState } from "react";
const pad = (n: number) => String(n).padStart(2, "0");
const isoDate = (date: Date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
export default function DatePickerBasic() {
const [date, setDate] = useState<Date | null>(new Date(2026, 7, 17));
return (
<div style={{ display: "grid", gap: 12, justifyItems: "center" }}>
<DatePicker value={date} onChange={setDate} />
<Tag minimal>{date ? `Release cut: ${isoDate(date)}` : "No release date"}</Tag>
</div>
);
}Shortcuts#
shortcuts adds a menu beside the calendar. true shows presets relative to today, such as Yesterday and 1 week ago. An array of { label, date } objects shows your own.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { DatePicker, type DatePickerShortcut } from "@clawscale/react/datetime";
const milestones: DatePickerShortcut[] = [
{ label: "Code freeze", date: new Date(2026, 7, 12) },
{ label: "Release cut", date: new Date(2026, 7, 17) },
{ label: "Canary at 10%", date: new Date(2026, 7, 19) },
{ label: "General availability", date: new Date(2026, 7, 24) },
];
export default function DatePickerShortcuts() {
return <DatePicker shortcuts={milestones} defaultValue={new Date(2026, 7, 17)} />;
}Minimum and maximum dates#
minDate and maxDate limit the days a user can pick. Days outside the range are disabled, and the month and year menus only list months inside it. The defaults are January 1st, 20 years ago, and 6 months from today.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { DatePicker } from "@clawscale/react/datetime";
// Backfills can only target days inside the 90-day retention window.
export default function DatePickerMinMax() {
return (
<DatePicker minDate={new Date(2026, 5, 3)} maxDate={new Date(2026, 7, 31)} defaultValue={new Date(2026, 7, 17)} />
);
}Time precision#
timePrecision adds a time picker under the calendar: minute, second or millisecond. Picking another day keeps the time. Configure the time picker with timePickerProps, for example { useAmPm: true }.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { Tag } from "@clawscale/react";
import { DatePicker } from "@clawscale/react/datetime";
import { useState } from "react";
const pad = (n: number) => String(n).padStart(2, "0");
const format = (date: Date) =>
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
export default function DatePickerTimePrecision() {
const [date, setDate] = useState<Date | null>(new Date(2026, 7, 17, 2, 30));
return (
<div style={{ display: "grid", gap: 12, justifyItems: "center" }}>
<DatePicker timePrecision="minute" value={date} onChange={setDate} />
<Tag minimal>{date ? `Deploy window opens ${format(date)}` : "No deploy window"}</Tag>
</div>
);
}Footer actions#
showActionsBar adds Today and Clear buttons under the calendar. Rename them with todayButtonText and clearButtonText. For other content, pass an element to footerElement.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
import { DatePicker } from "@clawscale/react/datetime";
export default function DatePickerActionsBar() {
return <DatePicker showActionsBar clearButtonText="Unschedule" defaultValue={new Date(2026, 7, 17)} />;
}Interactive playground#
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Props interface#
interface DatePickerProps extends Omit<DatePickerBaseProps, "dayPickerProps" | "locale" | "modifiers">, DateFnsLocaleProps, ReactDayPickerSingleProps, Props@clawscale/react/datetime| Props | Description |
|---|---|
canClearSelection | boolean = trueAllows the user to clear the selection by clicking the currently selected day. If disabled, the "Clear" Button in the Actions Bar will also be disabled. |
className | stringA space-delimited list of class names to pass along to a child element. Inherited from Props |
clearButtonText | string = "Clear"Text for the reset button in the action bar. |
dateFnsLocaleLoader | DateFnsLocaleLoaderOptional custom loader function for the date-fns Inherited from Locale which will be used to localize the date picker. This is useful in test environments or in build systems where you wish to customize module loading behavior. If not provided, a default loader will be used which uses dynamic imports to load date-fns/locale/${localeCode} modules.DateFnsLocaleProps |
dayPickerProps | Omit<DayPickerSingleProps, ReactDayPickerOmittedProps>Props to pass to react-day-picker's single day picker. See API documentation here. Inherited from ReactDayPickerSingleProps |
defaultValue | DateInitial day the calendar will display as selected. This should not be set if value is set. |
footerElement | React.JSX.ElementAn additional element to show below the date picker. Inherited from DatePickerBaseProps |
highlightCurrentDay | boolean = falseWhether the current day should be highlighted in the calendar. Inherited from DatePickerBaseProps |
initialMonth | DateThe initial month the calendar displays. Inherited from DatePickerBaseProps |
locale | Locale | string = "en-US"date-fns Inherited from Locale object or locale code string ((ISO 639-1 + optional country code) which will be used to localize the date picker.DateFnsLocaleProps |
maxDate | Date = 6 months from now.The latest date the user can select. Inherited from DatePickerBaseProps |
minDate | Date = Jan. 1st, 20 years in the past.The earliest date the user can select. Inherited from DatePickerBaseProps |
onChange | (selectedDate: Date | null, isUserChange: boolean) => voidCalled when the user selects a day. If being used in an uncontrolled manner, selectedDate will be null if the user clicks the currently selected day. If being used in a controlled manner, selectedDate will contain the day clicked no matter what. isUserChange is true if the user selected a day, and false if the date was automatically changed by the user navigating to a new month or year rather than explicitly clicking on a date in the calendar. |
onShortcutChange | (shortcut: DatePickerShortcut, index: number) => voidCalled when the shortcuts props is enabled and the user changes the shortcut. |
reverseMonthAndYearMenus | boolean = falseIf Inherited from true, the month menu will appear to the left of the year menu. Otherwise, the month menu will apear to the right of the year menu.DatePickerBaseProps |
selectedShortcutIndex | numberThe currently selected shortcut. If this prop is provided, the component acts in a controlled manner. |
shortcuts | boolean | DatePickerShortcut[]Whether shortcuts to quickly select a date are displayed or not. If true, preset shortcuts will be displayed. If false, no shortcuts will be displayed. If an array is provided, the custom shortcuts will be displayed. |
showActionsBar | boolean = falseWhether the bottom bar displaying "Today" and "Clear" buttons should be shown. |
timePickerProps | TimePickerPropsFurther configure the Inherited from TimePicker that appears beneath the calendar. onChange and value are ignored in favor of the corresponding top-level props on this component.DatePickerBaseProps |
timePrecision | TimePrecisionThe precision of time selection that accompanies the calendar. Passing a Inherited from TimePrecision value (or providing timePickerProps) shows a TimePicker below the calendar. Time is preserved across date changes.DatePickerBaseProps |
timezone | stringThe currently selected timezone UTC identifier, e.g. "Pacific/Honolulu". |
todayButtonText | string = "Today"Text for the today button in the action bar. |
value | Date | nullThe currently selected day. If this prop is provided, the component acts in a controlled manner. |