Markdown:
Components

DateField

A form control wrapper for Temporal.PlainDate values, default DateInput composition, and date validation.

Usage

Use standalone, or wrap DateInput to share field state and validation.

Svelte
<DateField {...props} />

<DateField {...props}>
  <DateInput {...props} />
</DateField>

Anatomy

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

Svelte
<div class="whole" role="group" aria-*>
  <div class="top" conditional>
    <label class="label" conditional>
      {label}
      <span class="extra" conditional>{extra}</span>
    </label>
    <span class="aux" conditional>{aux}</span>
  </div>
  <div class="middle">
    <span class="left" conditional>{left}</span>
    {#if children}{@render children()}{:else if native}<input class="main" type="date" aria-* />{:else}<DateInput />{/if}
    <span class="right" conditional>{right}</span>
    <input hidden conditional />
  </div>
  <div class="bottom" conditional>{bottom}</div>
</div>

Props

NameTypeDefaultDescription
labelstring-Field label
extrastring-Extra text shown with the label
auxSnippet-Auxiliary content; receives value, variant, and input element
leftSnippet-Content before the control
rightSnippet-Content after the control
bottomstring-Bottom message
reservebooleanfalseRenders the bottom element even without a message to prevent layout shift
valueTemporal.PlainDate-Bindable selected date
minTemporal.PlainDate-Minimum allowed date
maxTemporal.PlainDate-Maximum allowed date
requiredbooleanfalseStandard date required constraint owned by the field
disabledbooleanfalseStandard disabled constraint owned by the field
validationsDateFieldValidation-Field-level validation functions for the selected date
namestring-Form submission name for the hidden canonical ISO input
nativebooleanfalseUses a browser <input type="date">; dateInput options do not apply
elementHTMLInputElement-Bindable input element
stylingSVSClass-Styling override
variantSVSVariantNEUTRALBindable variant
dateInputOmit-Props for the default inner DateInput; ignored when children is supplied
childrenSnippet-Compound form child DateInput that shares the field state

Styling

To learn more, see Styling.

Variant Management

In the initial state or while no value is set, neutral is applied. After a value is set, the variant switches to active if validation succeeds or inactive if validation fails. If the variant prop is specified, the specified value is used instead of neutral.

Default Class Name

svs-date-field

Behavior

  • In the default path, one hidden attribute input carries the canonical ISO form value and all constraint validation, including when DateInput is readonly.
  • native uses a browser-provided <input type="date">; dateInput options do not apply in that mode.

Accessibility

ARIA Roles and Attributes

The component applies these automatically:

  • Field (whole <div>): role="group" and aria-labelledby pointing to the label part when label text is present.
  • Date control: aria-describedby, aria-invalid, and aria-errormessage from the validation message wiring. In the default mode, DateInput also receives aria-required when required is set; in native mode, the date input uses the native required attribute.

Provide label text for the field's accessible name; the component wires that label to the group and control instead of requiring an author-passed aria-label. In the default non-native mode, picker keyboard and ARIA behavior come from DateInput.

Standards Basis

When native is set, DateField is built on a native <input type="date">, so keyboard and assistive-technology support follows the browser standard for date inputs. See the Concepts standards-first guidance for the library's approach.

Exports

Types

TypeScript
type DateFieldValidation = SVSFieldValidation<Temporal.PlainDate | undefined>;
interface DateFieldProps {
  label?: string;
  extra?: string;
  aux?: Snippet<[Temporal.PlainDate | undefined, string, HTMLInputElement | undefined]>;
  left?: Snippet<[Temporal.PlainDate | undefined, string, HTMLInputElement | undefined]>;
  right?: Snippet<[Temporal.PlainDate | undefined, string, HTMLInputElement | undefined]>;
  bottom?: string;
  reserve?: boolean; // (false)
  value?: Temporal.PlainDate; // bindable
  min?: Temporal.PlainDate;
  max?: Temporal.PlainDate;
  required?: boolean; // (false)
  disabled?: boolean; // (false)
  validations?: DateFieldValidation[];
  name?: string;
  native?: boolean; // (false)
  element?: HTMLInputElement; // bindable
  styling?: SVSClass;
  variant?: SVSVariant; // bindable (VARIANT.NEUTRAL)
  dateInput?: Omit<
    DateInputProps,
    DateInputReqdProps | DateInputBindProps | "name" | "min" | "max" | "required" | "disabled" | "variant" | "styling"
  >;
  children?: Snippet;
}
type DateFieldReqdProps = never;
type DateFieldBindProps = "value" | "variant" | "element";

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