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
import { DatePicker } from "@hackcove/ui";
<DatePicker label="Date of birth" description="As on your ID document." />
DatePicker: DD/MM/YYYY segments the person can type, and a calendar button for the rest.import { Input } from "@hackcove/ui";
<Input aria-label="Date of birth" placeholder="DD/MM/YYYY" />
Error
import { DatePicker } from "@hackcove/ui";
<DatePicker
label="Paid on"
description="The day the money moved."
error="That date is before the invoice."
/>error: it replaces the description and is announced as an alert.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
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>
);
}CalendarDate. fromISODate reads a stored YYYY-MM-DD, toISODate writes it back, and name posts the same string in a form.Typed only
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
DatePickeror aDateField, never anInput. The format is always DD/MM/YYYY and weeks start on Monday, whatever the browser's locale. DatePickeradds a calendar button;DateFieldis the same input without it, for a date the person knows by heart (a birthday).- These two draw their own label: give them
labelanddescription, and do not wrap them in aField. - 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.isInvalidalone marks the field with no reason, so pair it witherrorMessage. - The value is a
CalendarDate(value,defaultValue,onChange,minValue,maxValue).fromISODatereads a storedYYYY-MM-DDandtoISODatewrites one. nameposts the date asYYYY-MM-DDin 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
descriptionis the field'saria-describedby; theerrorand the built-in messages replace it, and anerrorisrole="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
DialogorDrawerthe 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.
defaultOpenOpen the calendar on mount.
- Type
boolean
descriptionA hint under the field; an error replaces it.
- Type
ReactNode
errorAn 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
errorMessageReplaces the built-in error message (an impossible date, or one outside min/max).
- Type
ReactNode
isInvalidMarks 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.
descriptionA hint under the field; an error replaces it.
- Type
ReactNode
errorAn 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
errorMessageReplaces the built-in error message (an impossible date, or one outside min/max).
- Type
ReactNode
isInvalidMarks the field invalid with no message of its own; pair it with errorMessage.
- Type
boolean
label- Type
ReactNode
Functions
fromISODateReads a stored"YYYY-MM-DD"into theCalendarDatea picker takes;nullfor an empty, malformed or impossible string.toISODateWrites aCalendarDateas"YYYY-MM-DD", or""for none, so it drops into a form field or storage.