Date Field
A date field asks for a date as three parts, day, month and year, in a <fieldset> named by its <legend>, with optional helper text and an error message, all linked by generated ids. It suits dates people know by heart, such as a date of birth, where a calendar picker is slower than typing.
Status: beta — implemented and unit-tested in all seven frameworks with an axe-clean demo page; not yet exercised in composed flows.
The value prop is bindable and is an ISO 8601 date once all three parts are filled. The order of the parts is the consumer's (order), and so are the part labels: there is no English or regional default. Error messages are announced to screen readers via role="alert", and each part carries aria-invalid while an error is shown.
Example
Show demo markup
<fieldset class="date-field" aria-describedby="demo-dob-desc"><legend>Date of birth</legend><label for="demo-dob-day">Day</label><input class="date-field-day" id="demo-dob-day" name="dob-day" type="text" inputmode="numeric" autocomplete="bday-day" maxlength="2" value="27" /><label for="demo-dob-month">Month</label><input class="date-field-month" id="demo-dob-month" name="dob-month" type="text" inputmode="numeric" autocomplete="bday-month" maxlength="2" value="03" /><label for="demo-dob-year">Year</label><input class="date-field-year" id="demo-dob-year" name="dob-year" type="text" inputmode="numeric" autocomplete="bday-year" maxlength="4" value="2007" /><p id="demo-dob-desc">For example, 27 3 2007</p></fieldset>
Usage example
<script lang="ts">
import DateField from "./DateField.svelte";
let start = $state("");
</script>
<DateField
label="Start date"
bind:value={start}
/>
Show Svelte source
// In your Svelte component:
import DateField from "lily-design-system-svelte-headless/components/DateField/DateField.svelte";
<DateField>
<!-- content -->
</DateField>
Usage
Date of birth, day first:
<DateField
label="Date of birth"
dayLabel="Day"
monthLabel="Month"
yearLabel="Year"
order="dmy"
name="dob"
autocomplete="bday"
value="{dateOfBirth}"
description="For example, 27 3 2007"
required
/>
With a validation error, year first:
<DateField
label="Appointment date"
dayLabel="Day"
monthLabel="Month"
yearLabel="Year"
value="{appointmentDate}"
error="The date must be in the future"
required
/>
Props
label: string (required) -- the legend, naming the whole date
dayLabel: string (required when precision is "day") -- the day part's label
monthLabel: string (required unless precision is "year") -- the month part's label
yearLabel: string (required) -- the year part's label
order: "ymd" | "dmy" | "mdy" (default: "ymd") -- the order of the parts
precision: "day" | "month" | "year" (default: "day") -- how much of the date is asked for: a month asks for month and year ("onset: March 2019"), a year for the year alone; rendered as data-precision when not "day"
value: string (default: "") -- the date as YYYY-MM-DD, YYYY-MM or YYYY (by precision), or "" while a part is empty; two-way bindable. A partial date is never padded with an invented day or month
name: string (default: undefined) -- base name; the parts are {name}-day, {name}-month, {name}-year
autocomplete: "bday" (default: undefined) -- a date of birth: the parts autocomplete as bday-day, bday-month, bday-year (WCAG 1.3.5)
description: string (default: undefined) -- helper text, linked from the fieldset
error: string (default: undefined) -- error message, linked from the fieldset and announced
required: boolean (default: false) -- every part is required
disabled: boolean (default: false) -- the fieldset and its parts are disabled
id: string (default: undefined) -- base id for the parts; auto-generated if omitted
Keyboard Interactions
Tab moves between the three parts; each is a native text field.
ARIA
<fieldset> + <legend> -- the group's name, which a screen reader announces with each part
<label for> -- names each part
aria-describedby -- on the <fieldset>, the description and the error when present
aria-invalid="true" -- on each part while an error is shown
role="alert" -- on the error paragraph, announces the error message to screen readers
When to Use
- Use for structured date entry with separate fields for day, month, and year.
- Use when more control over individual date parts is needed than a plain DateInput provides.
- Use when you want built-in ARIA linking between the label, input, description, and error message without manual ID management.
- Use for forms that require date input with validation feedback, description text, and error display in a single integrated component.
- Use when accessibility-compliant date entry is essential, such as in healthcare or government forms.
When Not to Use
- Do not use for known exact dates where a simple DateInput is sufficient.
- Do not use for calendar-based date selection -- use CalendarTable or CalendarRangePicker instead.
- Do not use when you need a bare date input with custom label placement; use DateInput instead.
Headless
This headless DateField component provides a <fieldset> and <legend>, three labelled part fields, an optional description <p>, and an optional error <p> with role="alert", linked from the fieldset by aria-describedby. The consumer provides all visual styling including label typography, input appearance, description and error text colors, and layout.
Styles
The consumer provides all CSS styling. The component renders with a .date-field class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<fieldset> element with class date-field, a <legend>, and the three parts in order
- Verify role="alert"` -- on the error paragraph, announces the error message to screen readers
- Verify pass-through attributes are applied
Advice
- Designers: Place the description text below the label and above the input to set expectations before users interact. Display error messages in a contrasting color near the input.
- Developers: Use the bindable
value prop for two-way date state; it stays "" until all three parts are filled, so validate the parts on submit. Pick order for your users' convention (ISO 8601 ymd by default). The auto-generated ids handle the ARIA linking.
Implementation Notes
- Renders a
<fieldset> named by a <legend> (label), holding three labelled text fields for the day, month and year parts (inputmode="numeric"), an optional description <p>, and an optional error <p role="alert">
order sets the order of the parts: "ymd" (ISO 8601, the default), "dmy" or "mdy"; the component picks no regional order of its own
- The part labels (
dayLabel, monthLabel, yearLabel) are required for the parts shown and have no default: the words are the consumer's, in their language
precision "month" or "year" leaves out the day, or the day and month: the value is YYYY-MM or YYYY, never a full date with an invented day (openEHR DV_DATE partial dates, FHIR date); format it for display with formatPartialDate() from clinical-format
value is two-way: an ISO 8601 date (YYYY-MM-DD) when all three parts are filled, or "" while any is empty; a new value fills the parts
- Each part is named
{name}-day, {name}-month and {name}-year, so a server-rendered form submits without script
- Auto-generates a unique base id when none is given; the parts are
{id}-day, {id}-month, {id}-year, and the description and error {id}-desc and {id}-error
Related components
date-input — an input for entering a date value <input type="date">
date-range — paired start and end date inputs
calendar-range-picker — a picker for selecting a date range on a calendar
Known limitations
None known.
References
Lily™ and Lily Design System™ are trademarks.
Canonical contract
Generated from this component's canonical metadata — the machine-checked source the implementations are held to.
Metadata
- Component: date-field
- PascalCase: DateField
- Description: a structured field for entering date components
- Purpose: Asks for a date as day, month and year in separate boxes, for dates people know by heart such as a birth date.
- Status: beta — implemented and unit-tested in all seven frameworks with an axe-clean demo page; not yet exercised in composed flows
- HTML tag: <fieldset>
- CSS class: .date-field
- Interactive: no
ARIA
<fieldset> + <legend> -- the group's name, which a screen reader announces with each part <label for> -- names each part aria-describedby -- on the <fieldset>, the description and the error when present aria-invalid="true" -- on each part while an error is shown role="alert" -- on the error paragraph, announces the error message to screen readers
Keyboard
- Tab moves between the parts; each part is a native text field
Props
label: string (required) -- the legend, naming the whole date dayLabel: string (required when precision is "day") -- the day part's label monthLabel: string (required unless precision is "year") -- the month part's label yearLabel: string (required) -- the year part's label order: "ymd" | "dmy" | "mdy" (default: "ymd") -- the order of the parts precision: "day" | "month" | "year" (default: "day") -- how much of the date is asked for: a month asks for month and year ("onset: March 2019"), a year for the year alone; rendered as data-precision when not "day" value: string (default: "") -- the date as YYYY-MM-DD, YYYY-MM or YYYY (by precision), or "" while a part is empty; two-way bindable. A partial date is never padded with an invented day or month name: string (default: undefined) -- base name; the parts are {name}-day, {name}-month, {name}-year autocomplete: "bday" (default: undefined) -- a date of birth: the parts autocomplete as bday-day, bday-month, bday-year (WCAG 1.3.5) description: string (default: undefined) -- helper text, linked from the fieldset error: string (default: undefined) -- error message, linked from the fieldset and announced required: boolean (default: false) -- every part is required disabled: boolean (default: false) -- the fieldset and its parts are disabled id: string (default: undefined) -- base id for the parts; auto-generated if omitted
Markdown
This page as Markdown, for people and AI tools: date-field.md