Date picker
A date field with a calendar dialog: type the date or pick it.
Example
<div class="stack"> <focsd-date-picker label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></focsd-date-picker></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-picker.js';</script>
<focsd-date-picker label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></focsd-date-picker>import { DatePicker } from '@focsd-dev/react';
export function Example() { return <DatePicker onChange={(e) => console.log(e.target)} label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></DatePicker>;}<script setup>import '@focsd-dev/components/focsd-date-picker.js';</script>
<template> <focsd-date-picker @change="onChange" label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></focsd-date-picker></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-date-picker.js';
// template<focsd-date-picker (change)="onChange($event)" label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></focsd-date-picker><script> import '@focsd-dev/components/focsd-date-picker.js';</script>
<focsd-date-picker onchange={(e) => console.log(e.target)} label="Departure" value="2026-03-14" min="2026-03-05" locale="en-GB"></focsd-date-picker>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
name | name | string | — |
disabled | disabled | boolean | false |
required | required | boolean | false |
readonly | readOnly | boolean | false |
aria-label | hostAriaLabel | string | null | null |
aria-description | hostAriaDescription | string | null | null |
aria-labelledby | hostAriaLabelledBy | string | null | null |
aria-describedby | hostAriaDescribedBy | string | null | null |
label-position | labelPosition | 'top' | 'start' | 'end' | undefined | — |
hint | hint | string | — |
error | error | — | — |
warning | warning | string | undefined | — |
success | success | string | undefined | — |
error-message | errorMessage | string | undefined | — |
warning-message | warningMessage | string | undefined | — |
warning-pattern | warningPattern | string | undefined | — |
label | label | string | — |
value | value | string | — |
min | min | string | — |
max | max | string | — |
locale | locale | string | — |
step | step | number | 1 |
autocomplete | autocomplete | AutoFill | off |
Methods
| Method | Description |
|---|---|
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. |
showPicker() | Open the calendar from code, like native showPicker(). |
openDialog() | Open the calendar dialog and focus its active day. Does nothing while disabled or read-only. |
Events
| Event | Description |
|---|---|
input | Fired on every user edit of the value. |
change | Fired 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-picker::part(calendar).
| Part | Description |
|---|---|
calendar | The calendar inside the dialog. |
calendar-day | Calendar parts, re-exported with a `calendar-` prefix (calendar-day, calendar-nav, calendar-heading, calendar-grid, calendar-weekday, calendar-today, calendar-selected, …). |
panel | The dialog's content: the calendar, any extra fields and the actions. |
actions | The row of dialog buttons at the bottom. |
cancel | The dialog's Cancel button (also exposed as `close`). |
close | The dialog's Cancel button (kept for existing stylesheets). |
control | The control element. |
dialog | The dialog element. |
field | The field element. |
label | The label element. |
layout | The wrapper that places the label beside or above the body. |
body | The control, hint and message. |
hint | The author hint followed by the date format. |
message | The shown error, warning or success message (also `error`, `warning` or `success`). |
message-icon | The message's icon. |
announcer | The visually hidden status region. |
trigger | The trigger element. |
Accessibility
autocomplete,step(in days),valueAsDate,valueAsNumberandshowPicker()work as on a native date input.- Typing is always allowed: the input shows the expected format ("YYYY-MM-DD") in its description and reports invalid or out-of-range dates.
- The "Choose date" button opens a modal
<dialog>labeled "Choose date"; focus lands on the selected day and returns to the button on close. - Form-associated: participates in
FormData, validation, reset, fieldsetdisabledand back/forward restore.
Keyboard
| Key | Action |
|---|---|
| Enter (in the input) | Submit the form |
| Calendar keys | As the calendar |
| Escape | Close the dialog without changing |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.