v1.5

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

pnpm dlx @create-ui/cli add date-input

The command also adds input-group and the useDateInput hook.

Usage

import { DateInput } from "@/components/ui/date-input"
<Field>
  <FieldLabel htmlFor="birth-date">Date of birth</FieldLabel>
  <DateInput
    id="birth-date"
    onValueChange={(iso, date) => console.log(iso, date)}
  />
</Field>

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.

<DateInput order="MDY" />
<DateInput order="YMD" />

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.

<DateInput
  onValueChange={(iso, date) => {
    if (!date) return // the date is not complete yet
    console.log(date.getFullYear(), date.getMonth() + 1, date.getDate())
  }}
/>

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.

<DateInput defaultValue="2026-12-31" />
<DateInput defaultValue="31 / 12 / 2026" />
<DateInput order="YMD" defaultValue="2026 / 12 / 31" />

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.

const [iso, setIso] = React.useState("")
 
<DateInput value={iso} onValueChange={(next) => setIso(next)} />

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}.

<DateInput showLeadingIcon={false} />

Accessibility

DateInput renders a real text input inside an InputGroup, with inputMode="numeric" for a numeric keyboard.

KeyDescription
TabMoves focus into the input.
Shift + TabMoves focus out of the input.
EnterSubmits the surrounding <form> when present.

ARIA notes:

  • Give the input a name with FieldLabel htmlFor, aria-label or aria-labelledby. Do not rely on the placeholder, which shows the format.
  • The calendar icon is decorative and is not a control.
  • aria-invalid and error styling follow invalid, directly or from a parent Field. Pair it with a FieldError so the message is announced.
  • The component sets no autocomplete value. Pass autoComplete yourself where a field matches a browser token. A masked DD / MM / YYYY value 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:

<DateInput className="w-[220px]" />

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.
  • 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 DateInput is 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

PropTypeDefaultDescription
defaultValuestring-ISO string, YYYY-MM-DD, or the masked display string such as "31 / 12 / 2026".
valuestring-Controlled value in the same forms as defaultValue. "" clears it.
onChangeReact.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.
placeholderstringfrom orderDefaults to the format, such as "DD / MM / YYYY". Pass it only to override.
invalidboolean-Marks the field invalid. Inherits from Field.
disabledboolean-Disables the field. Inherits from Field.
loadingboolean-Shows a spinner. Inherits from Field.
showLeadingIconbooleantrueShows the calendar icon.
leadingReactNodecalendar iconReplaces the icon.
classNamestring-Tailwind classes merged on the group.
refReact.Ref<HTMLInputElement>-Ref to the inner input.

Variants

VariantOptionsDefaultDescription
size"xs" "sm" "md""sm"Height and type scale. Omit it inside Field; the size comes from there.