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.
<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.
<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
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Field label |
extra | string | - | Extra text shown with the label |
aux | Snippet | - | Auxiliary content; receives value, variant, and input element |
left | Snippet | - | Content before the control |
right | Snippet | - | Content after the control |
bottom | string | - | Bottom message |
reserve | boolean | false | Renders the bottom element even without a message to prevent layout shift |
value | Temporal.PlainDate | - | Bindable selected date |
min | Temporal.PlainDate | - | Minimum allowed date |
max | Temporal.PlainDate | - | Maximum allowed date |
required | boolean | false | Standard date required constraint owned by the field |
disabled | boolean | false | Standard disabled constraint owned by the field |
validations | DateFieldValidation | - | Field-level validation functions for the selected date |
name | string | - | Form submission name for the hidden canonical ISO input |
native | boolean | false | Uses a browser <input type="date">; dateInput options do not apply |
element | HTMLInputElement | - | Bindable input element |
styling | SVSClass | - | Styling override |
variant | SVSVariant | NEUTRAL | Bindable variant |
dateInput | Omit | - | Props for the default inner DateInput; ignored when children is supplied |
children | Snippet | - | 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
DateInputis readonly. nativeuses a browser-provided<input type="date">;dateInputoptions do not apply in that mode.
Accessibility
ARIA Roles and Attributes
The component applies these automatically:
- Field (
whole<div>):role="group"andaria-labelledbypointing to the label part when label text is present. - Date control:
aria-describedby,aria-invalid, andaria-errormessagefrom the validation message wiring. In the default mode,DateInputalso receivesaria-requiredwhenrequiredis set; innativemode, the date input uses the nativerequiredattribute.
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
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.