Date Input
Masked type-in date field with a configurable day, month and year order. It reports an ISO string and a Date once the date is complete.
Description
DateInput is a text field for typing a date. The user types digits and the mask adds the / separators in the chosen order: DMY (the default), MDY or YMD. A calendar icon sits at the start of the field. The icon is decoration only; it does not open a picker.
When every part of the date is filled in, onValueChange reports an ISO string and a Date. Until then it reports "" and null.
Use it when people know the date and type it fast, such as a birth date. Use the Pro DatePicker when people should pick from a calendar. For free text, use Input.
Installation
The command also adds input-group and the useDateInput hook.
Usage
Examples
With a label
Wrap the input in Field, add a FieldLabel, and tie them together with id and htmlFor. Field does not wire the id for you. size, invalid, disabled and loading flow from Field when you leave them unset on the input.
Order
order sets the segment order and the placeholder: DD / MM / YYYY, MM / DD / YYYY or YYYY / MM / DD. The order is read once when the component mounts. To switch it at run time, remount the component with a new key.
Reading the value
onValueChange receives an ISO string and a Date. Use the Date argument. The ISO string comes from toISOString() on a date at local midnight, so it is a UTC timestamp, and its date part can differ from the typed day outside the UTC time zone.
Seeding a value
defaultValue takes an ISO string, a plain YYYY-MM-DD (read as a local date) or the masked display string in the active order.
Controlled
Pass value with onValueChange to own the value in the parent. value takes the ISO string that onValueChange emits (a plain YYYY-MM-DD or the masked text also work). onValueChange fires for typed changes only: setting value from the parent updates the field without firing it again, and "" clears a complete date. While a date is only partly typed, onValueChange emits "" and the field keeps the text, so setting value to "" again does not clear it.
With React Hook Form, wire it through Controller so the form stores the ISO string and reset() refills the field. register() works for submit only: it collects the masked text, and reset() and setValue() do not update the field.
Mask limits
Day and month pad themselves (5 becomes 05). The day runs from 1 to 31, the month from 1 to 12, and the year from 1900 to 2100. Values outside these ranges cannot be typed.
Icon
Replace the icon with leading, or hide it with showLeadingIcon={false}.
Accessibility
DateInput renders a real text input inside an InputGroup, with inputMode="numeric" for a numeric keyboard.
| Key | Description |
|---|---|
Tab | Moves focus into the input. |
Shift + Tab | Moves focus out of the input. |
Enter | Submits the surrounding <form> when present. |
ARIA notes:
- Give the input a name with
FieldLabel htmlFor,aria-labeloraria-labelledby. Do not rely on the placeholder, which shows the format. - The calendar icon is decorative and is not a control.
aria-invalidand error styling followinvalid, directly or from a parentField. Pair it with aFieldErrorso the message is announced.- The component sets no
autocompletevalue. PassautoCompleteyourself where a field matches a browser token. A maskedDD / MM / YYYYvalue may not match the format the browser fills in, so test it before you rely on it.
Styling
Tailwind override: pass className to restyle the group:
Data slots: the component uses the InputGroup slots:
data-slot="input-group"on the group.data-slot="input-group-slot"on the slot that holds the icon and the input.data-slot="input-group-control"on the input.
Related Components
- Date Picker: Pro. A trigger styled like an input that opens a calendar.
- Calendar: Pro. A calendar for single dates, multiple dates and ranges.
- Input Group: the shell
DateInputis built from. - Field: adds the label, description and error footer.
- Phone Input and Credit Card Input: other masked fields built on
InputGroup.
API Reference
DateInput
Extends React.ComponentProps<"input"> minus size. Standard attributes such as id, name, required and aria-* reach the inner <input>. Seed an uncontrolled field with defaultValue, or control it with value and onValueChange.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | string | - | ISO string, YYYY-MM-DD, or the masked display string such as "31 / 12 / 2026". |
value | string | - | Controlled value in the same forms as defaultValue. "" clears it. |
onChange | React.ChangeEventHandler<HTMLInputElement> | - | Fires once per accepted keystroke with the masked text. For register(). |
order | "DMY" "MDY" "YMD" | "DMY" | Segment order. Read once on mount. |
onValueChange | (iso: string, date: Date | null) => void | - | iso is "" and date is null until every segment is complete. |
placeholder | string | from order | Defaults to the format, such as "DD / MM / YYYY". Pass it only to override. |
invalid | boolean | - | Marks the field invalid. Inherits from Field. |
disabled | boolean | - | Disables the field. Inherits from Field. |
loading | boolean | - | Shows a spinner. Inherits from Field. |
showLeadingIcon | boolean | true | Shows the calendar icon. |
leading | ReactNode | calendar icon | Replaces the icon. |
className | string | - | Tailwind classes merged on the group. |
ref | React.Ref<HTMLInputElement> | - | Ref to the inner input. |
Variants
| Variant | Options | Default | Description |
|---|---|---|---|
size | "xs" "sm" "md" | "sm" | Height and type scale. Omit it inside Field; the size comes from there. |