DatePicker

A date in DD/MM/YYYY segments, with a calendar to pick from.

Overview

Any date a person enters; use DateField when a calendar is not wanted.

Date

Do
Date of birth
As on your ID document.
import { DatePicker } from "@hackcove/ui";

<DatePicker label="Date of birth" description="As on your ID document." />
A date is a DatePicker: DD/MM/YYYY segments the person can type, and a calendar button for the rest.
Don't
import { Input } from "@hackcove/ui";

<Input aria-label="Date of birth" placeholder="DD/MM/YYYY" />
A text input takes any characters, so 17/5/90, 1990-05-17 and "May" all arrive, and nothing says which is meant.

Error

Do
Paid on
That date is before the invoice.
import { DatePicker } from "@hackcove/ui";

<DatePicker
  label="Paid on"
  description="The day the money moved."
  error="That date is before the invoice."
/>
A message from outside the field, a server's say, is error: it replaces the description and is announced as an alert.
Don't
Paid on
import { DatePicker } from "@hackcove/ui";

<DatePicker label="Paid on" description="The day the money moved." isInvalid />
isInvalid alone turns the field red and says nothing about why.

Value

Do
Paid on
Stored as 2026-10-26.
import { Caption, DatePicker, fromISODate, Stack, toISODate } from "@hackcove/ui";
import { useState } from "react";

function Example() {
  const [paid, setPaid] = useState(fromISODate("2026-10-26"));
  return (
    <Stack gap="xs">
      <DatePicker label="Paid on" name="paidOn" value={paid} onChange={setPaid} />
      <Caption>Stored as {toISODate(paid) || "nothing yet"}.</Caption>
    </Stack>
  );
}
The value is a CalendarDate. fromISODate reads a stored YYYY-MM-DD, toISODate writes it back, and name posts the same string in a form.

Typed only

Do
Date of birth
DDMMYYYY
DD/MM/YYYY
import { DateField } from "@hackcove/ui";

<DateField label="Date of birth" description="DD/MM/YYYY" />
DateField is the same input without the calendar button, for a date the person knows by heart.

Usage

  • A date is a DatePicker or a DateField, never an Input. The format is always DD/MM/YYYY and weeks start on Monday, whatever the browser's locale.
  • DatePicker adds a calendar button; DateField is the same input without it, for a date the person knows by heart (a birthday).
  • These two draw their own label: give them label and description, and do not wrap them in a Field.
  • A message from outside, a server's say, is error; it replaces the description. An impossible date, such as 31/02/1990, shows its own message. isInvalid alone marks the field with no reason, so pair it with errorMessage.
  • The value is a CalendarDate (value, defaultValue, onChange, minValue, maxValue). fromISODate reads a stored YYYY-MM-DD and toISODate writes one.
  • name posts the date as YYYY-MM-DD in a form, or an empty string.

Accessibility

  • The label names a role="group"; each of day, month and year is its own editable segment (role="spinbutton"), so a person can type digits or use the arrow keys.
  • The description is the field's aria-describedby; the error and the built-in messages replace it, and an error is role="alert".
  • The calendar button is labelled "Calendar" and opens a popover dialog, with a Month and a Year select, arrow-key movement across days and a Clear button.
  • Inside a Dialog or Drawer the calendar opens inside it, so it still takes focus.
  • The focus ring comes from the component.

API

DatePicker

A DateField with a calendar button that opens a month view in a popover.


defaultOpen

Open the calendar on mount.

Type
boolean

description

A hint under the field; an error replaces it.

Type
ReactNode

error

An error from outside the field (a server's, say). Shown in place of the description, in red with role="alert", and marks the field invalid. Like Field's error.

Type
ReactNode

errorMessage

Replaces the built-in error message (an impossible date, or one outside min/max).

Type
ReactNode

isInvalid

Marks the field invalid with no message of its own; pair it with errorMessage.

Type
boolean

label
Type
ReactNode

DateField

A segmented DD / MM / YYYY date input. Values are CalendarDates; name posts it as YYYY-MM-DD.


description

A hint under the field; an error replaces it.

Type
ReactNode

error

An error from outside the field (a server's, say). Shown in place of the description, in red with role="alert", and marks the field invalid. Like Field's error.

Type
ReactNode

errorMessage

Replaces the built-in error message (an impossible date, or one outside min/max).

Type
ReactNode

isInvalid

Marks the field invalid with no message of its own; pair it with errorMessage.

Type
boolean

label
Type
ReactNode

Functions

  • fromISODate Reads a stored "YYYY-MM-DD" into the CalendarDate a picker takes; null for an empty, malformed or impossible string.
  • toISODate Writes a CalendarDate as "YYYY-MM-DD", or "" for none, so it drops into a form field or storage.