# 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 ``` ## Anatomy The `class` attribute values represent part names, and `conditional` indicates elements that are rendered conditionally. Other attributes represent their corresponding props. ```svelte
{aux}
{left} {#if children}{@render children()}{:else if native}{:else}{/if} {right}
{bottom}
``` ## 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 ``; `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](/docs/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 ``; `dateInput` options do not apply in that mode. ## Accessibility ### ARIA Roles and Attributes The component applies these automatically: - Field (`whole` `
`): `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](/docs/date-input). ### Standards Basis When `native` is set, DateField is built on a native ``, so keyboard and assistive-technology support follows the browser standard for date inputs. See the [Concepts standards-first guidance](/docs/concepts) for the library's approach. ## Exports ### Types ```ts type DateFieldValidation = SVSFieldValidation; 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 **Code** ```svelte src=DateFieldBasic.svelte
Selected: {value?.toString() ?? "Pick a day"}
{#snippet preserve()}{/snippet} {#snippet left()}{"<"}{/snippet} {#snippet right()}{">"}{/snippet} ``` ### With Interactive Variant **Code** ```svelte src=DateFieldPract.svelte
Selected: {value?.toString() ?? "Pick a day"}
{#snippet preserve()}{/snippet} {#snippet left()}{"<"}{/snippet} {#snippet right()}{">"}{/snippet} ```