Skip to content
Focsd homeFocsd homeFocsd
Forms

Date field

A date typed into day, month and year segments, in the order the locale uses.

  • Tag: focsd-date-field
  • Pattern: Spinbutton segments (day, month, year)
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-date-field
label="Date of birth"
name="dob"
value="1990-03-15"
locale="en-US"></focsd-date-field>
<focsd-date-field
label="Start date"
name="start"
locale="en-GB"
min="2026-01-01"
max="2026-12-31"
hint="Any day in 2026"></focsd-date-field>
<focsd-date-field label="Deadline" name="deadline" required></focsd-date-field>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-date-field.js';
</script>
<focsd-date-field label="Date of birth" name="dob" value="1990-03-15" locale="en-US"></focsd-date-field>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevalue——
minminstring—
maxmaxstring—
localelocalestring—

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

CSS parts

Style the inside of the component with ::part(), for example focsd-date-field::part(field).

PartDescription
fieldThe group that holds the segments.
segmentEach day, month or year segment (also `day`, `month` or `year`).
literalThe separators between segments.
labelThe label element.
layoutThe wrapper that places the label beside or above the body.
bodyThe field, hint and message.
hintThe author's hint.
messageThe shown error, warning or success message (also `error`, `warning` or `success`).
message-iconThe message's icon.
announcerThe visually hidden status region.

Accessibility

  • A labeled role="group" of role="spinbutton" segments named "Day", "Month" and "Year", in the order the locale writes them. The month segment speaks its name ("March") through aria-valuetext; an empty segment reads "Empty".
  • Impossible dates, such as February 30 or February 29 in a year that is not a leap year, are never moved to a nearby day: value stays empty and the field reports "Enter a real date, such as 2026-02-28."
  • A year only counts once all four digits are typed. Leaving a segment halfway through clears it, so "19" is never read as the year 19.
  • Pasting 2026-10-15, or a date written in the locale order such as 15/10/2026 in en-GB, fills every segment. Only digits count: a two-digit year, or a date with a month name such as "Oct 15, 2026", is ignored.
  • min, max, required and valueAsDate work as on a native date input, with plain messages for each. The form value is always YYYY-MM-DD.
  • Form-associated: participates in FormData, validation, reset, fieldset disabled and back/forward restore. Restore brings back a half-typed date.

Keyboard

KeyAction
Arrow Up / DownChange the segment; wraps at the ends
DigitsType a value; moves on when complete
Arrow Left / RightPrevious / next segment
Backspace / DeleteClear the segment; Backspace on an empty segment moves to the previous one
PasteFill every segment from an ISO or locale date