Skip to content
Home Theme Gallery

Date picker

The custom element is <hui-date-picker>.

Overview

A form-associated text input with a calendar in a popover. Typing an ISO date and picking a day produce the same value, and what is submitted is always ISO whatever the display locale.

Example

Date picker
Source
<hui-date-picker name="due" value="2024-02-15" aria-label="Due date"></hui-date-picker>

The Go template that renders it:

<hui-date-picker name="{{ .Name }}" value="{{ .Value }}" min="{{ .Min }}" max="{{ .Max }}" aria-label="{{ .Label }}"></hui-date-picker>

API

Attributes10
Attributes
NameTypeDefaultDescription
namestring""The form field name. Without one the control submits nothing.
valuestring""The selected ISO date. Reflects to the value attribute; a non-ISO value submits nothing.
placeholderstring"YYYY-MM-DD"Placeholder shown in the input while it is empty.
requiredbooleanfalseMarks the field required and blocks submission while no valid date is set.
minstring""Inclusive lower bound, forwarded to the calendar and the input.
maxstring""Inclusive upper bound, forwarded to the calendar and the input.
localestring""BCP 47 locale for the embedded calendar.
week-startnumber0First day of the week for the embedded calendar, 0 for Sunday.
openbooleanfalseWhether the calendar panel is open. Reflects to the open attribute.
disabledbooleanfalseDisables the input and the toggle, and prevents the panel from opening.
Properties10
Properties
NameTypeDefaultDescription
namestring''Reflects to the name attribute.
valuestring''Reflects to the value attribute.
placeholderstring'YYYY-MM-DD'Reflects to the placeholder attribute.
requiredbooleanfalseReflects to the required attribute.
minstring''Reflects to the min attribute.
maxstring''Reflects to the max attribute.
localestring''Reflects to the locale attribute.
week-startnumber0Reflects to the week-start attribute.
openbooleanfalseReflects to the open attribute.
disabledbooleanfalseReflects to the disabled attribute.
Events4
Events
NameDescription
inputEmitted on the host when a day is picked, a typed date is committed or the field is cleared. It bubbles and is composed.
changeEmitted alongside input for the same commits. It bubbles and is composed.
hui-openEmitted when the calendar panel opens, including via the platform popover's light dismiss. It bubbles and is composed.
hui-closeEmitted when the calendar panel closes. It bubbles and is composed.
CSS custom properties5
CSS custom properties
NameDefaultDescription
--hui-popoveroklch(1 0 0)Background of the calendar panel.
--hui-inputoklch(0.62 0.019 323.02)Border of the field, and of the invalid field.
--hui-destructiveoklch(0.56 0.245 27.325)Border of the field while aria-invalid="true".
--hui-radius-mdcalc(var(--hui-radius, 0.45rem) * 0.8)Corner radius of the field and the panel.
--hui-muted-foregroundoklch(0.542 0.034 322.5)Colour of the calendar toggle glyph.
::part() hooks4
::part() hooks
NameDescription
fieldThe bordered container that anchors the panel.
inputThe internal native text input.
toggleThe "Choose date" button.
panelThe popover containing the hui-calendar.

States

Empty

With no value the trigger shows its placeholder until a date is chosen.

Empty
Source
<hui-date-picker name="other" placeholder="YYYY-MM-DD" aria-label="Other date"></hui-date-picker>

Bounded and required

Bounds and required, passed through to both the calendar inside and the form outside.

Bounded and required
Source
<hui-date-picker name="slot" value="2024-02-15" min="2024-02-10" max="2024-02-20" required aria-label="Slot"></hui-date-picker>

Disabled

Disabled: the trigger does not open and the value still submits nothing.

Disabled
Source
<hui-date-picker name="locked" value="2024-02-15" disabled aria-label="Locked date"></hui-date-picker>

Server-side mechanics

The server renders <hui-date-picker> with a name and an ISO value, plus optional min, max, required, locale and week-start. It is form-associated: the ISO date submits under that name, a malformed typed date submits nothing and blocks submission, and with no name it submits nothing. The server must not send calendar markup, because the element builds the embedded <hui-calendar> itself. An hx-swap that replaces the picker while its panel is open closes the panel and discards any date typed but not committed.

Accessibility

  • The internal input is the form control and receives the host's aria-label and aria-invalid.
  • A malformed typed date sets badInput; required with no valid date sets valueMissing, both reported through ElementInternals.
  • The toggle has the accessible name "Choose date".
  • The calendar panel is a native popover="auto", so the platform supplies light dismiss.

Keyboard

Keyboard
KeysAction
Printable charactersType an ISO date; a valid one commits to the form, a malformed one blocks submission.
Enter, SpaceActivate the toggle to open or close the calendar.
Calendar grid keysOnce open, the embedded calendar handles arrows, Page Up/Down and Home/End; Enter or Space picks the focused day and closes the panel.

Gotchas

  • The picker does not emit hui-select: it listens for the embedded calendar's hui-select and stops it, so only the synthetic input and change escape to the host.
  • The submitted value is always ISO; a non-ISO value, or a half-typed date, submits nothing and is reported as badInput or valueMissing through ElementInternals.