DateInput
A text-like date control with a private Calendar popover and Temporal.PlainDate binding.
Usage
Use standalone; it owns a private Calendar for date selection and can later be coordinated by DateField.
<DateInput {...props} />Anatomy
The class attribute values represent part names, and conditional indicates elements that are rendered conditionally. Other attributes represent their corresponding props.
<span class="whole" data-* style>
<span class="left" conditional>{left}</span>
<input class="main" type="text" role="combobox" aria-* {...rest} />
<span class="right" conditional>{right}</span>
<input type="hidden" conditional />
<div class="bottom" conditional>{#if children}{children}{:else}<Calendar />{/if}</div>
</span>Props
| Name | Type | Default | Description |
|---|---|---|---|
value | Temporal.PlainDate | - | Bindable selected date; undefined means empty |
open | boolean | false | Bindable private calendar popover open state |
min | Temporal.PlainDate | - | Minimum allowed date |
max | Temporal.PlainDate | - | Maximum allowed date |
isDisabled | function | - | Disables dates matching a custom predicate |
parse | function | - | Caller-coordinated text parser; enables typed value entry |
format | function | - | Caller-coordinated display formatter |
locale | string | - | Locale used by the default formatter and private calendar |
name | string | - | Emits a hidden input with the ISO date string |
openOnFocus | boolean | true | Opens the popover when the input receives focus |
closeOnSelect | boolean | true | Closes the popover after a date is selected |
left | Snippet | - | Content before the input; receives control helpers, open state, and variant |
right | Snippet | - | Content after the input; receives control helpers, open state, and variant |
transition | TransitionProp | - | Optional transition function and params for the popover |
children | Snippet | - | Declarative Calendar child; self-wires value/min/max/isDisabled/variant and wins over calendar |
calendar | Omit | - | Nested config bag spread into the private Calendar |
cssvar | object | - | Custom-property names for the overlay x/y offsets and z-index; absent key uses the default name |
attach | Attachment | - | Svelte attachment on the input |
element | HTMLInputElement | - | Bindable input element |
styling | SVSClass | - | Styling override |
variant | SVSVariant | NEUTRAL | Variant |
Other HTMLInputAttributes are passed to <input> via rest props; class is merged onto the root.
Styling
To learn more, see Styling.
Variant Management
No automatic switching.
Default Class Name
svs-date-input
Behavior
- Without
parse, the visible control is readonly and the private calendar is the only value entry path. - With
parse, draft text commits on change or blur; invalid, disabled, and out-of-range dates revert. - With
parse, opening keeps focus in the input for typing; press ArrowDown to move focus into the calendar. Withoutparse, opening moves focus into the calendar. - A declarative
Calendarchild self-wiresvalue,min,max,isDisabled, andvariantthrough context and wins over thecalendarbag. nameis assigned only to a hidden input whose value is ISO (Temporal.PlainDate.toString()), not the locale-formatted control.formatandparseare caller-coordinated; the default locale display is not necessarily parseable by a supplied parser.- The
wholewrapper isposition:relative;display:inline-block;because the overlay anchors against it; a caller overriding itsdisplayowns the resulting anchor geometry. - The overlay defaults below/left, flips per axis above/right on viewport overflow, exposes
data-svs-flip-x/data-svs-flip-yon flipped axes, and reads its offsets fromcssvarx/y custom properties (defaults--svs-position-x/--svs-position-y). - The overlay carries
z-index: var(--svs-position-z, 1)so it paints above adjacent positioned content (e.g. a followingDateInput's relatively-positioned root). Override it from caller CSS or rename it via thecssvarz key to fit a caller's own stacking order.
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Escape | Closes the open date-picker overlay and returns focus to the input |
When parse is provided, typing edits the date text. openOnFocus opens the overlay when the input receives focus. For date navigation inside the open picker, see Calendar.
ARIA Roles and Attributes
The component applies these automatically:
- Input (
main):role="combobox",aria-haspopup="dialog",aria-expanded,aria-controlswhile the overlay is open,aria-describedby,aria-invalid, andaria-errormessage. - Overlay (
bottom): itsidis referenced byaria-controlswhile open and it contains the privateCalendar.
Provide an accessible name yourself because there is no built-in visible label. Pass aria-label or aria-labelledby through the rest props, or associate a <label> with the input. The component manages the ARIA attributes listed above for its own state and validation wiring.
Exports
Types
type TransitionProp = {
fn?: (node: HTMLElement, params: any, options: { direction: "in" | "out" | "both" }) => import("svelte/transition").TransitionConfig;
params?: unknown;
};
type DateInputCtl = {
toggle: () => void;
show: () => void;
hide: () => void;
clear: () => void;
};
interface DateInputProps extends Omit<HTMLInputAttributes, "type" | "value" | "min" | "max" | "readonly" | "list" | "name"> {
value?: Temporal.PlainDate; // bindable; undefined = empty
open?: boolean; // bindable (false)
min?: Temporal.PlainDate;
max?: Temporal.PlainDate;
isDisabled?: (d: Temporal.PlainDate) => boolean;
parse?: (text: string) => Temporal.PlainDate | undefined;
format?: (d: Temporal.PlainDate) => string;
locale?: string;
name?: string;
openOnFocus?: boolean; // (true)
closeOnSelect?: boolean; // (true)
left?: Snippet<[DateInputCtl, boolean, string]>;
right?: Snippet<[DateInputCtl, boolean, string]>;
transition?: TransitionProp;
children?: Snippet;
calendar?: Omit<CalendarProps, "value" | "display" | "min" | "max" | "isDisabled" | "variant">;
cssvar?: Partial<Record<DateInputCssVar, string>>; // custom-property names for the overlay x/y offsets and z-index; absent key uses default name
attach?: Attachment<HTMLInputElement>;
element?: HTMLInputElement; // bindable
styling?: SVSClass;
variant?: SVSVariant; // (VARIANT.NEUTRAL)
}
type DateInputReqdProps = never;
type DateInputBindProps = "value" | "open" | "element";
type DateInputCssVar = "x" | "y" | "z";Others
No additional exports are available.
Examples
The example code uses Tailwind CSS along with SVSClass.