Date Input
catnip-input-date is a combobox field with a calendar dialog. Keyboard support, screen-reader names and announcements, focus handling, and Windows contrast theme styles are built in. You provide the label, your own validation messages, and the reasons behind unavailable dates.
Keyboard
Field
| Key | Behaviour |
|---|---|
| Arrow Down / Alt + Arrow Down | Opens the panel and moves focus into it: the selected preset (or the first one), otherwise the active day. |
| Enter | Commits the typed value and closes the panel; with Apply in the panel, works as Apply. |
| Tab | Closes the panel and moves on, like any combobox. |
| Escape | Closes the panel. |
Focusing the field never opens the panel; a click opens it and keeps focus in the field. Each time the panel opens it shows the selected date (the range start, or today when nothing is selected), not the month browsed last time.
Panel
| Key | Behaviour |
|---|---|
| Tab / Shift + Tab | Moves between the panel's controls; focus wraps inside the panel. |
| Escape | Closes the panel and returns focus to the field. With Apply, also discards the draft like Cancel. |
The panel closes on Escape, Tab from the field, picking a date (single date without time), Apply, Cancel, or a click outside. Focus returns to the field after every close except a click outside. A visually hidden Close button (not in the Tab order) is added when the panel has no Cancel, so touch screen reader users can dismiss it.
Presets
| Key | Behaviour |
|---|---|
| Arrow Up / Arrow Down | Previous / next preset. |
| Home / End | First / last preset. |
| Enter / Space | Pick the focused preset. |
The list has one Tab stop: the focused, otherwise selected, preset.
Calendar
| Key | Behaviour |
|---|---|
| Arrow Left / Right | Move active day backward / forward. |
| Arrow Up / Down | Move active day by one week. |
| Home / End | Move to the start / end of the active week. |
| PageUp / PageDown | Move to the previous / next month. |
| Shift + PageUp / Shift + PageDown | Move to the same month in the previous / next year. |
| Enter / Space | Select active date. |
Arrow keys stop at min and max. Unavailable days (disabled-dates, or past max-range-days while picking the end) can be focused and are announced as unavailable, but not selected. The calendar has one Tab stop, on the active day, even with two months shown.
The month/year header button opens a year grid. In range mode it also opens a month grid: years on the left and months on the right in the horizontal dual-month panel, or years above months in the vertical stack. Selecting a year updates the month grid; selecting a month returns to the day calendars. Single-date mode still uses the year grid only. In the year grid, arrow keys move between years, PageUp / PageDown move between year ranges, and Enter / Space selects the active year. In the month grid, arrows move between months and Enter / Space selects the active month.
Screen readers
| Part | Semantics |
|---|---|
| Field | <input role="combobox"> with aria-haspopup="dialog", aria-expanded, aria-autocomplete="none", and aria-controls while open. Described by its expected format and the supporting text; intent="danger" sets aria-invalid="true". |
| Panel | role="dialog" named "{label}, Choose date" (or "Choose dates" in range mode). aria-modal="true" only while focus is inside. Rendered right after the field, so reading order and Tab order follow it; shown in the top layer. |
| Month | <table role="grid"> named by month and year; weekday column headers carry the full weekday name; each day is a button in a role="gridcell". |
| Day names | Full date, then as applicable: "today", "unavailable", "selected", "start of selected range", "end of selected range". Today also has aria-current="date". |
| Live region | Polite. Announces "Start date {date}. Choose an end date.", "Selected range: {range}", and the month shown after the previous / next buttons. |
| Preset field | While a named preset is shown, its dates are added to the field's description; while the field has focus it shows the dates and describes "Preset: {name}". |
| Time fields | Labeled text inputs (HH:mm), not native time pickers. |
Override these strings through registerTranslate: inputDate.chooseDate, inputDate.chooseDates, inputDate.close, inputDate.presetDescription, and the shared calendar keys calendar.today ("today"), calendar.selected ("selected"), calendar.rangeStart ("start of selected range"), calendar.rangeEnd ("end of selected range"), calendar.unavailable ("unavailable"), calendar.startChosen ("Start date {date}. Choose an end date."), calendar.rangeSelected ("Selected range: {range}"), and calendar.dateSelected ("Selected: {date}"). Existing inputDate.* keys for navigation (for example inputDate.previousMonth) still take precedence over their calendar.* equivalents.
info renders a button after the label, named “More information about {label}” and described by the info text, which shows as a tooltip on hover and focus; Escape hides it. Content in label.action and label.suffix sits beside the <label>, not inside it, so it isn't part of the field's name.
Visual
- The field shows a focus ring. In Windows contrast themes the field's border and focus ring, the time fields' focus, and the calendar's selection, range band, today, and focus all show in system colours.
- The value stays on one line and scrolls inside the field when it doesn't fit; below 800px a horizontal range panel switches to the stacked layout.
What you own
- Label: Set
label(or thelabelslot), also withhide-label: the hidden label text still names the field. Useinput-date-aria-labelonly when the accessible name should differ. Don't usedisplay-formatplaceholders such asDD/MM/YYYYas the label. - From / To fields: In the vertical range-with-time panel, set
start-labelandend-labelwhen the defaults don't fit. - Validation messages: When typed text can't be read, the field adds a format message (
inputDate.invalidFormat) after yoursupporting-text. Every other rule is yours: setintent="danger"and say what's wrong and how to fix it insupporting-text. On submit, move focus to the first invalid field or an error summary. - Limits: When
min,max, ormax-range-daysmatter, state them insupporting-text. - Unavailable dates: Screen reader users hear that a day is unavailable, not why. Explain
disabled-datesin nearby supporting text when the reason isn't obvious. - Custom trigger: With
slot="trigger", put the slot on a focusable control and give it an accessible name. The field setsaria-haspopup="dialog"andaria-expandedon it. - Translations: Register translations for the strings above with
registerTranslate, and setlocalewhen the app locale differs from the browser's. - Outside label or description: A
<label for>orcatnip-field-label html-forthat points at thecatnip-input-dateelement'sidnames the inner control when the field has no label of its own, and clicking it focuses the field. IDs inaria-describedby(ariaDescribedby) are looked up in the page, or in the shadow root the element sits in, and read before the supporting text. Both are connected through element reflection; axe-core 4.11 doesn't read reflection yet and still reportslabelfor an outside label.
WCAG 2.2 AA
| Criterion | The component | You |
|---|---|---|
| 1.3.1 Info and relationships, 4.1.2 Name, role, value | Combobox field named by the label; dialog, grid, and listbox roles; day names include today, selection, range ends, and unavailability; aria-invalid with intent="danger" | A label on every field |
| 2.1.1 Keyboard, 2.1.2 No keyboard trap | APG date-grid keys; one Tab stop per calendar and preset list; Escape always closes the panel | Don't capture keys globally while the field has focus |
| 2.4.3 Focus order | The panel follows the field in the DOM; focus returns to the field after Escape, a pick, Apply, and Cancel | Keep source order and visual order the same |
| 2.4.7 Focus visible | Visible focus on the field and in the panel, including Windows contrast themes | Don't override focus styles |
| 3.2.1 On focus | Focusing the field never opens the panel | Don't submit or navigate when the value changes |
| 3.3.1 Error identification, 3.3.3 Error suggestion | Unreadable typed text stays in the field and is flagged with a format message | Messages for your own rules, and focus on the first invalid field on submit |
| 3.3.2 Labels or instructions | The expected format is part of the field's description | State limits such as min, max, and max-range-days |
| 4.1.3 Status messages | Polite announcements for the range start, the completed range, month changes, and the format message | Announce results that depend on the date yourself, for example availability loaded from a server |
This table says who handles what. It isn't a conformance claim: WCAG conformance is claimed for a page or a process.
Known issues
None known.