Skip to content

HyDateField ​

Usage examples on this page are written for Lit / plain HTML (<hy-date-field>). The same component ships as HyDateField in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A locale-aware segmented date, date-time or time input. Each unit (month / day / year; hour / minute in datetime and time, plus AM/PM on a 12-hour clock) is an arrow-adjustable, type-to-edit spinbutton — the keyboard-first, screen-reader-friendly replacement for a readonly trigger. No calendar; compose with hy-date-picker for the popover.

Independently form-associated — usable standalone with its own name / value and form-control surface (hy-date-picker composes it rather than re-implementing).

Value is ISO YYYY-MM-DD (date), YYYY-MM-DDTHH:MM (datetime) or HH:MM (time), always 24-hour. Segment order, separators and the 12- or 24-hour clock come from the resolved locale via Intl; hour-cycle overrides the clock. On a 12-hour clock the hour arrows cycle within AM or PM and the AM/PM segment switches the period (React Aria's model); A / P set it. min / max compare what the field holds: a date, a full date-time (a date-only bound on a date-time field allows that whole day), or a time.

When to use

  • A date people know without looking at a calendar: a birth date, an expiry date.
  • A time of day, with type="time".

Do

  • Set min and max when only some dates are valid.

When not to use

  • A date people choose by looking at a calendar, where the weekday matters: hy-date-picker.
  • A start and an end date: hy-date-picker range.
  • Showing a date without editing it: the date as text, or hy-relative-time.
  • A duration such as 45 minutes: hy-number-input with a suffix.

Accessibility: your part ​

  • When you set min or max, tell people the allowed range. An entry outside it never commits.

Examples ​

html
<hy-date-field label="Start date" value="2026-03-07"></hy-date-field>
<hy-date-field type="datetime" label="Starts at"></hy-date-field>
<hy-date-field type="time" label="Opens at" value="09:00"></hy-date-field>
<hy-date-field
  type="time"
  label="Shift start"
  min="06:00"
  max="22:00"
  hour-cycle="24"
></hy-date-field>
<hy-date-field label="Arrival" helper-text="The day you check in."></hy-date-field>
<hy-date-field
  label="Arrival"
  value="2026-03-08"
  warning-message="That is a Sunday: the desk is closed."
></hy-date-field>
<hy-date-field label="Arrival" error-message="Pick a date after today."></hy-date-field>

The line under the field shows the error message, else the warning message, else the helper text. error paints the danger color and sets aria-invalid on the segments; warning paints the warning color at rest and never touches aria-invalid or form validity. Setting a message raises its flag and clearing it lowers it.

API ​

Properties ​

PropertyAttributeTypeDefaultDescription
valuevaluestring''ISO value: YYYY-MM-DD (date), YYYY-MM-DDTHH:MM (datetime) or HH:MM (time), always 24-hour.
typetype'date' | 'datetime' | 'time''date'date (default), datetime (adds hour and minute) or time (hour and minute only).
hourCyclehour-cycle12 | 24—12 or 24-hour display for datetime and time. Unset follows the locale (en-US 12, de-CH 24). The value is 24-hour either way.
minminstring | undefined——
maxmaxstring | undefined——
localelocalestring | undefined——
labellabelstring''—
helperTexthelper-textstring''Helper text shown under the field while no error or warning message replaces it.
errorMessageerror-messagestring''Error message shown under the field (replaces the helper text). Setting it raises error.
errorerrorbooleanfalseError state: the value is not accepted. Paints the danger color and sets aria-invalid on the segments. Visual and for screen readers only — it never blocks submission.
warningMessagewarning-messagestring''Warning message shown under the field (replaces the helper text). Setting it raises warning.
warningwarningbooleanfalseWarning state: the value is accepted but worth a second look. Paints the warning color at rest and shows warning-message; never sets aria-invalid and never blocks submission. error wins when both are set.
disableddisabledbooleanfalse—
requiredrequiredbooleanfalseMarks the field as required for form validation: while it is empty, checkValidity() is false and native submission is blocked, with the browser's own message on the first segment. The label gets the mark.
namenamestring''—
sizesize'small' | 'medium' | 'large''medium'—
widthwidthstring | undefined——
autofocusautofocusbooleanfalse—
strings—Partial<DateFieldStrings>{}The built-in strings — the segments' accessible names, their placeholders, the empty announcement and the AM / PM fallback. Only the keys set replace the English defaults (DEFAULT_DATE_FIELD_STRINGS). Use for internationalization.
form—HTMLFormElement | null——
validity—ValidityState——

Events ​

EventDetailDescription
input—Fires on each segment edit that yields a complete valid value.
change—Fires on blur / Enter once all segments form a valid value.

CSS Parts ​

PartDescription
baseOuter wrapper (label, field, message line)
labelThe visible label
fieldThe segmented input row
segmentA single editable segment
helper-textHelper text
error-messageThe error message element
warning-messageThe warning message element
message-iconThe icon starting the error or warning message

CSS Custom Properties ​

The documented hooks. Every override hook the component reads — one per token it paints — is listed in @whitespaceux/harmony/theme-api.json, and @whitespaceux/harmony/component-bindings.json (the Harmony MCP get-bindings tool) says which part and state each one paints.

PropertyDefaultDescription
--hy-date-field-control-height-smvar(--hy-control-height-sm)Small-size outer height
--hy-date-field-control-height-mdvar(--hy-control-height-md)Medium-size outer height
--hy-date-field-control-height-lgvar(--hy-control-height-lg)Large-size outer height
--hy-date-field-foreground-danger-restvar(--hy-foreground-danger-rest)Error border, message text and icon color.
--hy-date-field-foreground-warning-restvar(--hy-foreground-warning-rest)Warning border (at rest), message text and icon color.
--hy-date-field-gap-layout-2xsvar(--hy-gap-layout-2xs)Gap between the message icon and its text.

Built with Lit. Documented with VitePress.