Date input
A DateInput is a text field with a calendar popover. Users type a date or pick one. Its value is an ISO 8601 string.
Usage#
import { DateInput } from "@clawscale/react/datetime";<DateInput dateFnsFormat="yyyy-MM-dd" value={value} onChange={setValue} />Examples#
Basic#
formatDate turns a Date into the text in the field. parseDate turns typed text back into a Date, or returns false for invalid text. For a date-fns format, pass dateFnsFormat instead, such as "dd MMM yyyy". Without either, the field uses yyyy-MM-dd.
import { FormGroup } from "@clawscale/react";
import { DateInput } from "@clawscale/react/datetime";
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const formatDate = (date: Date) => `${date.getDate()} ${MONTHS[date.getMonth()]} ${date.getFullYear()}`;
function parseDate(text: string) {
const [day = "", month = "", year = ""] = text.trim().split(/\s+/);
const date = new Date(Number(year), MONTHS.indexOf(month), Number(day));
// Reject unknown months and days that overflow, such as 31 Sep.
return MONTHS.includes(month) && date.getDate() === Number(day) ? date : false;
}
export default function DateInputBasic() {
return (
<FormGroup label="Retain audit logs until" labelFor="retain-until">
<DateInput
formatDate={formatDate}
parseDate={parseDate}
placeholder="D Mon YYYY"
defaultValue="2026-12-31"
inputProps={{ id: "retain-until" }}
/>
</FormGroup>
);
}Time precision#
timePrecision adds a time picker to the popover and the time to the text. onChange then receives an ISO string with an offset, such as "2026-08-17T02:30+00:00". showTimezoneSelect adds a timezone menu to the field.
defaultTimezone sets the first timezone. Without it, the field uses the user's timezone, which can differ between the server and the browser. Set it on server-rendered pages.
value: "2026-08-17T02:30+00:00"import { Code } from "@clawscale/react";
import { DateInput } from "@clawscale/react/datetime";
import { useState } from "react";
export default function DateInputTimePrecision() {
const [value, setValue] = useState<string | null>("2026-08-17T02:30+00:00");
return (
<div style={{ display: "grid", gap: 12, justifyItems: "start" }}>
<DateInput
timePrecision="minute"
showTimezoneSelect
defaultTimezone="Etc/UTC"
value={value}
onChange={setValue}
/>
<Code>value: {JSON.stringify(value)}</Code>
</div>
);
}Shortcuts#
shortcuts adds presets to the popover: Today, Yesterday, 1 week ago and more. Pass an array of { label, date } objects for your own.
import { DateInput } from "@clawscale/react/datetime";
export default function DateInputShortcuts() {
return <DateInput shortcuts defaultValue="2026-08-17" />;
}Controlled value#
Pass value and onChange to control the field. value is an ISO string, or null for an empty field. onChange receives null when the user clears the field. Text that does not parse calls onError instead.
value: "2026-08-17"import { Button, ButtonGroup, Code } from "@clawscale/react";
import { DateInput } from "@clawscale/react/datetime";
import { useState } from "react";
export default function DateInputControlled() {
const [value, setValue] = useState<string | null>("2026-08-17");
return (
<div style={{ display: "grid", gap: 12, justifyItems: "start" }}>
<DateInput value={value} onChange={setValue} />
<ButtonGroup>
<Button text="Release cut" onClick={() => setValue("2026-08-17")} />
<Button text="General availability" onClick={() => setValue("2026-08-24")} />
<Button text="Clear" onClick={() => setValue(null)} />
</ButtonGroup>
<Code>value: {JSON.stringify(value)}</Code>
</div>
);
}Props interface#
interface DateInputProps extends Omit<DatePickerBaseProps, "dayPickerProps" | "locale" | "modifiers">, ReactDayPickerSingleProps, DateFnsLocaleProps, Partial<Omit<DateFormatProps, "locale">>, DatetimePopoverProps, Props@clawscale/react/datetime| Props | Description |
|---|---|
canClearSelection | boolean = trueAllows the user to clear the selection by clicking the currently selected day. Passed to DatePicker component. |
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 date picker action bar. Passed to DatePicker component. |
closeOnSelection | boolean = trueWhether the calendar popover should close when a date is selected. |
dateFnsFormat | stringdate-fns format string used to format & parse date strings. |
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 |
defaultTimezone | stringThe default timezone selected. Defaults to the user's local timezone. |
defaultValue | stringThe default date to be used in the component when uncontrolled, represented as an ISO string. |
disabled | boolean = falseWhether the date input is non-interactive. |
disableTimezoneSelect | boolean = falseWhether to disable the timezone select. |
fill | booleanWhether the component should take up the full width of its container. |
footerElement | React.JSX.ElementAn additional element to show below the date picker. Inherited from DatePickerBaseProps |
formatDate | (date: Date, localeCode?: string | undefined): stringFunction to render a JavaScript Inherited from Date to a string. Optional localeCode argument comes directly from the prop on this component: if the prop is defined, then the argument will be too.DateFormatProps |
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 |
inputProps | Partial<Omit<InputGroupProps, "disabled" | "type" | "value">>Props to pass to the InputGroup component. |
invalidDateMessage | string = "Invalid date"The error message to display when the date selected is invalid. Inherited from DateFormatProps |
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 | (newDate: string | null, isUserChange: boolean) => voidCallback invoked whenever the date or timezone has changed. |
onError | (errorDate: Date) => voidCalled when the user finishes typing in a new date and the date causes an error state. If the date is invalid, new Date(undefined) will be returned. If the date is out of range, the out of range date will be returned (onChange is not called in this case). |
onTimezoneChange | (timezone: string) => voidCallback invoked when the user selects a timezone. |
outOfRangeMessage | string = "Out of range"The error message to display when the date selected is out of range. Inherited from DateFormatProps |
parseDate | (str: string, localeCode?: string | undefined): false | Date | nullFunction to deserialize user input text to a JavaScript Inherited from Date object. Return false if the string is an invalid date. Return null to represent the absence of a date. Optional localeCode argument comes directly from the prop on this component.DateFormatProps |
placeholder | stringPlaceholder text to display in empty input fields. Recommended practice is to indicate the expected date format. Inherited from DateFormatProps |
popoverProps | Partial<Omit<PopoverProps, "autoFocus" | "content" | "defaultIsOpen" | "disabled" | "enforceFocus" | "fill" | "renderTarget">>Props to spread to Inherited from Popover.DatetimePopoverProps |
popoverRef | React.RefObject<PopoverNextRef>Optional ref to the popover. Inherited from popoverRef.current?.reposition() re-runs position calculation, useful when the target moves in a way the popover doesn't observe automatically (e.g. a parent layout change that doesn't trigger a resize).DatetimePopoverProps |
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 |
rightElement | React.JSX.ElementElement to render on right side of input. |
shortcuts | boolean | DatePickerShortcut[] = falseWhether 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 below the calendar. |
showTimezoneSelect | boolean = falseWhether to show the timezone select dropdown on the right side of the input. If timePrecision is undefined, this will always be false. |
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 date picker action bar. Passed to DatePicker component. |
value | string | nullAn ISO string representing the selected time. |