Date Input
The catnip-input-date custom element lets users type or pick a single date, date and time, or date range from a floating calendar panel. It uses the same integrated label and supporting-text patterns as Input, Number Input, and Chip Input. Shared field behaviour is summarised on Inputs overview.
Overview
catnip-input-date values are canonical date strings, not UTC timestamps. Single-date values must use YYYY-MM-DD. Date-time values use YYYY-MM-DDTHH:mm without a timezone suffix, so they represent the selected calendar date and time rather than a converted UTC instant. Use display-format only to change the visible text in the input.
Every type uses one combined trigger: leading calendar icon, a single-line text field, optional clear control, and a chevron. The trigger fills the available width; a value longer than the field scrolls inside it. Clicking the field, or pressing Arrow Down, opens the calendar; focusing it does not. Use slot="value" to replace the typed text, or slot="trigger" to replace the whole shell.
- Single date:
model-value/.modelValueis a string inYYYY-MM-DDformat. Calendar selection commits immediately whenshow-timeis off. - Date and time: Set
show-timeto draftYYYY-MM-DDTHH:mmin the panel. Reset / Cancel / Apply confirm the value. - Range: Set
mode="range"to bind{ start?: string; end?: string }. The trigger shows both endpoints separated by an em dash. Date-only range commits when the end date is selected. Date-time range uses the same Apply footer as single date-time. - Range presets: Set
show-presetson range mode for the sidebar (Today, Last 7 days, Custom range, and so on). Named presets show their label in the trigger and switch to their dates while the field has focus, so they can be read and edited; an edit makes the range custom. Custom ranges show the date string. Optionalperiod-presetssubsets, reorders, or relabels the built-ins. Range values may includepreset. - Panel orientation:
panel-orientation="horizontal"(default) pages one month, or two side-by-side months in range mode. Range horizontal panels switch to the stacked vertical layout below 800px.verticalalways stacks a scrollable month list. - Display format: Set
display-formatanddisplay-date-time-formatwith Day.js-style format tokens to change visible input text only. Emitted values stay canonical. - Forgiving typing: Besides the display format, the field accepts other separators (
.,/,-, spaces), digits without separators (27031990), missing leading zeros, and month names, and rewrites the date in the display format on blur. See Specs — Typed input. - Inline clear: Shown by default when the field has a value. Set
show-clear-buttontofalseto hide it. - Constraints: Use
min,max, anddisabled-datesto block invalid calendar cells. In range mode, usemax-range-daysto cap the inclusive number of calendar days between start and end. - Calendar: Month navigation, a clickable month/year header, weekday headers, current/selected/range states, and keyboard navigation for day movement. In range mode the header opens a year grid beside a month grid (stacked in the vertical layout). Single date still opens the year grid only.
Live example
Guidelines
Use catnip-input-date when users need a calendar-backed date field, optional time selection, a start/end date range, or a range with named presets. For free-form text, use Input. For numeric values, use Number Input.
Behaviour
- Single date: Use the default
mode="single"for one date. Calendar clicks emit immediately whenshow-timeis off; valid typed values commit on Enter or blur. - Date and time: Add
show-timewhen a time matters. Values serialize asYYYY-MM-DDTHH:mm. The panel keeps a draft until Apply; Cancel discards it and Reset clears the draft. - Range: Use
mode="range"for start/end workflows such as travel dates, reporting windows, and eligibility periods. One combined trigger shows both endpoints. Default date-only range selection emits after the end date is selected. - Presets: Add
show-presetson range mode for rolling windows (Today, Last 30 days, This month, and so on). Named presets display their label in the trigger and their dates while the field has focus, so people can check or adjust them; editing the dates, or picking days in the calendar, switches to Custom range. All time keeps its label. Preset selection stays in draft until Apply. - Layout:
panel-orientation="horizontal"pages months (two months for range). Below 800px, range horizontal panels use the stacked vertical layout instead.verticalis always a stacked, scrollable month list.panel-placementandpanel-aligncontrol where the panel opens relative to the trigger; it still flips when space is tight. When the field shows supporting text, the panel opens below it so error messages stay visible. Give the field the width you can spare: the value stays on one line and scrolls inside the field when it doesn't fit. A date-time range needs about 400px to show in full. Withshow-presets, the preset list is a full-height left column; Reset / Cancel / Apply sit under the calendars only. - Clear: The inline clear control is shown by default when the field has a value. The panel Reset / Cancel / Apply row appears for
show-time,show-presets, or an explicitshow-actions. Clearing single mode emitsnull; clearing a range emits an empty range object. - Typing: Accept and store canonical strings. Use
display-formatfor visible text layouts and placeholders such asDD/MM/YYYYonly as hints; do not rely on placeholder text instead of a visible label. The field announces its format to screen readers, and also accepts other separators, missing leading zeros, digits without separators, and month names (useful for voice input), rewriting the date in the display format on blur. Text that doesn't parse stays in the field and is flagged on blur with a format message instead of being reverted or committed. Time boxes accept only digits and:, and expand shorthand such as930to09:30. On phones, a single date with an all-digitdisplay-formatbrings up a number pad. - Opening: The calendar opens on click or Arrow Down, never on focus alone, so keyboard users tabbing through a form aren't interrupted by a panel covering the next fields. Tab from the field closes it.
Constraints
- Bounds: Set
minandmaxwhen users must stay inside a known window. - Disabled dates: Use
disabled-datesfor specific unavailable days, e.g. holidays or maintenance windows. - Range length: Use
max-range-daysto cap range selections by inclusive calendar days, e.g.max-range-days="7"allows the start date plus the next six days. - Week start: Use
first-day-of-weekto match regional expectations. The default is1(Monday). - Locale: Set
localefor month and weekday labels when the app locale differs from the browser context.
Composition
- Labels:
labelprop orlabelslot above the single trigger.startLabel/endLabelprops or slots label the From / To datetime fields in the vertical range+time panel.label.action/label.suffixmatch Input on the group label only. - Custom value:
slot="value"replaces the typeable date text inside the default trigger (icon, clear, and chevron remain). The field is no longer typed — selection still goes through the calendar. - Custom trigger:
slot="trigger"replaces the whole field shell. Include a focusable control; click toggles the panel, and Enter / Space / Arrow Down open it with focus inside. Use this only when you need a non-field control (e.g. a button). - Supporting text: Pass
supporting-texton the host. Do not mountFieldSupportingTextmanually. - Status:
intentfollows the shared field model:neutral,warning,danger, andsuccess.
Best practices
- Prefer date-only mode unless the user truly needs a time.
- Use range mode only when both endpoints belong to the same decision.
- Use
show-presetsfor reporting windows and similar “last N days” choices; keep plain range when the user is picking two specific dates. - Match the display format to the product locale or workflow while keeping submitted values canonical for APIs and storage.
- Keep disabled dates explainable in nearby supporting text when the reason is not obvious. Screen reader users hear them as unavailable, but not why.
- Avoid forcing users to open the calendar for known dates; the field remains typeable unless you use
slot="value"orslot="trigger". - Let users jump by month and year from the header instead of repeatedly stepping month by month. In range mode the header shows years and months together. Keyboard users can also use Shift + PageUp / Shift + PageDown from the day grid.