Markdown:
Components

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.

Svelte
<DateInput {...props} />

Anatomy

The class attribute values represent part names, and conditional indicates elements that are rendered conditionally. Other attributes represent their corresponding props.

Svelte
<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

NameTypeDefaultDescription
valueTemporal.PlainDate-Bindable selected date; undefined means empty
openbooleanfalseBindable private calendar popover open state
minTemporal.PlainDate-Minimum allowed date
maxTemporal.PlainDate-Maximum allowed date
isDisabledfunction-Disables dates matching a custom predicate
parsefunction-Caller-coordinated text parser; enables typed value entry
formatfunction-Caller-coordinated display formatter
localestring-Locale used by the default formatter and private calendar
namestring-Emits a hidden input with the ISO date string
openOnFocusbooleantrueOpens the popover when the input receives focus
closeOnSelectbooleantrueCloses the popover after a date is selected
leftSnippet-Content before the input; receives control helpers, open state, and variant
rightSnippet-Content after the input; receives control helpers, open state, and variant
transitionTransitionProp-Optional transition function and params for the popover
childrenSnippet-Declarative Calendar child; self-wires value/min/max/isDisabled/variant and wins over calendar
calendarOmit-Nested config bag spread into the private Calendar
cssvarobject-Custom-property names for the overlay x/y offsets and z-index; absent key uses the default name
attachAttachment-Svelte attachment on the input
elementHTMLInputElement-Bindable input element
stylingSVSClass-Styling override
variantSVSVariantNEUTRALVariant

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. Without parse, opening moves focus into the calendar.
  • A declarative Calendar child self-wires value, min, max, isDisabled, and variant through context and wins over the calendar bag.
  • name is assigned only to a hidden input whose value is ISO (Temporal.PlainDate.toString()), not the locale-formatted control.
  • format and parse are caller-coordinated; the default locale display is not necessarily parseable by a supplied parser.
  • The whole wrapper is position:relative;display:inline-block; because the overlay anchors against it; a caller overriding its display owns 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-y on flipped axes, and reads its offsets from cssvar x/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 following DateInput's relatively-positioned root). Override it from caller CSS or rename it via the cssvar z key to fit a caller's own stacking order.

Accessibility

Keyboard Interactions

KeyDescription
EscapeCloses 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-controls while the overlay is open, aria-describedby, aria-invalid, and aria-errormessage.
  • Overlay (bottom): its id is referenced by aria-controls while open and it contains the private Calendar.

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

TypeScript
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.

Basic

With Interactive Variant

Preset for Demo
Enter variant as you like