When to use it#
- Use it for a date the user knows by heart, such as a date of birth. Put it in a
Fieldsetwhose legend asks the question. For a date of birth, setautoComplete="bday": each box then gets its own autofill token (1.3.5 Identify Input Purpose). - Use it in forms for residents and for staff, wherever the date is typed rather than picked. For a date near today, add a DatePicker button after the boxes: typing still works.
- For a date people read off a document, or most other dates, one TextInput with
masks.date()is shorter: one box and one Tab stop instead of three. It only checks the shape, so check the date withchecks.date. The calendar button and read-only examples below show it beside the boxes. - Not for a time or a month alone: use a TextInput with a mask or a Listbox.
Example#
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function BirthDate() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
return (
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday" />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
)
}Use cases#
A date that isn’t a birthday, and is optional
Leave autoComplete off: the token would offer the user’s own birthday (1.3.5 Identify Input Purpose). In a group Fieldset that isn’t required, the legend ends with “(optional)” and no box does.
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function VisitDate() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
return (
<Fieldset.Root group>
<Fieldset.Legend>{texts.visitLegend}</Fieldset.Legend>
<DateInput.Root name="visit" />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
)
}Props in this example:
nameon DateInput.Root
Saying which box is wrong
The date has one message, the Fieldset’s, and invalid goes on the wrong boxes only: “must include a year” marks Year, “must be a real date” marks all three. A box never has its own error message.
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function WrongYear() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
return (
<Fieldset.Root group required invalid>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root
name="birth"
autoComplete="bday"
defaultValue={{ day: '27', month: '3', year: '07' }}
invalidParts={['year']}
/>
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
<Fieldset.ErrorMessage>{texts.errorYear}</Fieldset.ErrorMessage>
</Fieldset.Root>
)
}Props in this example:
invalidPartson DateInput.RootdefaultValueon DateInput.Root
Warning: Don't forget
Keep the format example under the boxes when the error shows, and say how to fix it. See What you need to do.
In your own form state
Pass value and onValueChange from your form logic. The Root reports the whole date as the boxes show it: three strings, exactly as typed. It adds no zeros and does not turn them into a date. Checking it is your job. Write the strings as YYYY-MM-DD, with two digits for day and month, and pass that to checks.date.
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import type { DateInputValue } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateInputTexts } from './texts.ts'
export function ControlledDate() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
const [value, setValue] = useState<DateInputValue>({ year: '', month: '', day: '' })
return (
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday" value={value} onValueChange={setValue} />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
<p>
{texts.youEntered} {value.year}-{value.month}-{value.day}
</p>
</Fieldset.Root>
)
}Props in this example:
valueon DateInput.RootonValueChangeon DateInput.Root
In a plain form
Without value the browser keeps the text. name is a prefix, so a submit sends birth-day, birth-month and birth-year.
import { Button, DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateInputTexts } from './texts.ts'
export function PlainForm() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
const [sent, setSent] = useState<string | undefined>()
return (
<form
onSubmit={(event) => {
event.preventDefault()
const data = new FormData(event.currentTarget)
setSent(
(['year', 'month', 'day'] as const)
.map((part) => {
const text = data.get(`birth-${part}`)
return typeof text === 'string' ? text : ''
})
.join('-'),
)
}}
>
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday" />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
{sent === undefined ? null : (
<p>
{texts.sent} {sent}
</p>
)}
</form>
)
}Props in this example:
nameon DateInput.RootautoCompleteon DateInput.Root
A start date read off a document
When people copy the date from a letter or a decision, ask in one TextInput with masks.date() instead of three boxes. It has one Tab stop, and a pasted or autofilled date is reformatted. The mask follows the page’s locale, so write the example from the mask itself. The mask checks the shape only: check the date with checks.date.
For example 27/10/2026
The form state holds:
import { Field, TextInput, masks, useLocale } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateInputTexts } from './texts.ts'
export function OneFieldDate() {
const { texts } = useDateInputTexts()
const { locale } = useLocale()
const [stored, setStored] = useState('')
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<Field.Root required>
<Field.Label>{texts.oneFieldLabel}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
onValueChange={(_value, details) => setStored(details.unmaskedValue ?? '')}
/>
<Field.HelpText>{texts.oneFieldHint(example)}</Field.HelpText>
<p>
{texts.youEntered} {stored}
</p>
</Field.Root>
)
}Booking a time: type the date or pick it
For a date near today, put DatePicker.Trigger last in the row of boxes. Typing still works. The picker holds no date of its own: give it your date as value, and write the day the user picks back to your state. dateInputValueToIsoDate and isoDateToDateInputValue convert between the boxes and the picker. The second field is the one-box alternative from “When to use it”: maskedDateToIsoDate and isoDateToMaskedDate convert for it.
For example 27/10/2026
import {
DateInput,
DatePicker,
Field,
Fieldset,
TextInput,
dateInputValueToIsoDate,
isoDateToDateInputValue,
isoDateToMaskedDate,
maskedDateToIsoDate,
masks,
useDateInput,
useLocale,
} from '@kvirn-ui/react'
import type { DateInputValue } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateInputTexts } from './texts.ts'
const parts = { day: DateInput.Day, month: DateInput.Month, year: DateInput.Year }
export function DateWithPicker() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
const { locale } = useLocale()
const [boxes, setBoxes] = useState<DateInputValue>({ year: '', month: '', day: '' })
const [fieldText, setFieldText] = useState('')
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<>
<DatePicker.Root
value={dateInputValueToIsoDate(boxes)}
onValueChange={(isoDate) => setBoxes(isoDateToDateInputValue(isoDate))}
>
<Fieldset.Root group required>
<Fieldset.Legend>{texts.visitLegend}</Fieldset.Legend>
<DateInput.Root name="visit" value={boxes} onValueChange={setBoxes}>
{order.map((part) => {
const Box = parts[part]
return <Box key={part} />
})}
<DatePicker.Trigger />
</DateInput.Root>
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
<DatePicker.Popup />
</DatePicker.Root>
<DatePicker.Root
value={maskedDateToIsoDate(fieldText, locale)}
onValueChange={(isoDate) => setFieldText(isoDateToMaskedDate(isoDate, locale))}
>
<Field.Root required>
<Field.Label>{texts.oneFieldLabel}</Field.Label>
<div className="kv-date-picker-row">
<TextInput
name="start"
mask={masks.date()}
value={fieldText}
onValueChange={setFieldText}
/>
<DatePicker.Trigger />
</div>
<Field.HelpText>{texts.oneFieldHint(example)}</Field.HelpText>
</Field.Root>
<DatePicker.Popup />
</DatePicker.Root>
</>
)
}Information: Did you know?
Limits, closed days and the popup’s title are on the DatePicker page.
A date a case officer can see but not change
readOnly is for a staff tool that shows a date the user can’t change here. The boxes stay focusable and selectable, and a form submit still sends them. Say why in the help text. disabled (on the Root or the Fieldset) takes the boxes out of the Tab order and out of the submit, so use it only when nobody needs to read the value. In a resident form, avoid both and show the date as plain text. Turn auto-advance off: nothing can be typed, so its hint would only confuse.
You can’t change this date here. It comes from the application.
import { DateInput, Field, Fieldset, TextInput, masks } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function ReadOnlyDate() {
const { texts } = useDateInputTexts()
return (
<>
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root
name="birth"
readOnly
autoAdvance={false}
defaultValue={{ year: '1990', month: '3', day: '27' }}
/>
<Fieldset.HelpText>{texts.readOnlyReason}</Fieldset.HelpText>
</Fieldset.Root>
<Field.Root required>
<Field.Label>{texts.oneFieldLabel}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
readOnly
defaultValue="2026-10-27"
className="kv-input--width-10"
/>
<Field.HelpText>{texts.readOnlyReason}</Field.HelpText>
</Field.Root>
</>
)
}Props in this example:
readOnlyon DateInput.RootautoAdvanceon DateInput.Root
Your own wording for one date
Replace a string for one instance with messages: here the year box says “Year of birth”. The one field takes the mask’s messages the same way, for the line announced when a character is refused. To change a string for the whole service, set it once in the provider instead.
For example 27/10/2026
import {
DateInput,
Field,
Fieldset,
TextInput,
masks,
useDateInput,
useLocale,
} from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function OwnWordingDate() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
const { locale } = useLocale()
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<>
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday" messages={{ year: texts.birthYear }} />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
<Field.Root required>
<Field.Label>{texts.oneFieldLabel}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
messages={{ characterNotAllowed: () => texts.digitsOnly }}
className="kv-input--width-10"
/>
<Field.HelpText>{texts.oneFieldHint(example)}</Field.HelpText>
</Field.Root>
</>
)
}Props in this example:
messageson DateInput.Root
Matching a paper form
The order follows the region. When the service must match a paper form, write Day, Month and Year as children in the order you want, and write the example under the boxes in that order.
import { DateInput, Fieldset } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function PaperFormOrder() {
const { texts } = useDateInputTexts()
return (
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday">
<DateInput.Day />
<DateInput.Month />
<DateInput.Year />
</DateInput.Root>
<Fieldset.HelpText>{texts.hintDayFirst}</Fieldset.HelpText>
</Fieldset.Root>
)
}Typing never moves focus
By default, focus moves to the next box when typing fills one, and a visible hint says so before anyone types. If your service follows the stricter reading of 3.2.2 On Input, turn it off: the hint goes too.
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'
import { useDateInputTexts } from './texts.ts'
export function NoAutoAdvance() {
const { texts } = useDateInputTexts()
const { order } = useDateInput()
return (
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="birth" autoComplete="bday" autoAdvance={false} />
<Fieldset.HelpText>
{order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst}
</Fieldset.HelpText>
</Fieldset.Root>
)
}Props in this example:
autoAdvanceon DateInput.Root
Accessibility#
What it does for you#
- APG pattern: none. There is no APG pattern for a date field made of text boxes. A date is a group of three labelled text inputs inside a
<fieldset>with a<legend>, which is the pattern the GOV.UK Design System and other public-sector design systems use. Each box is a native input with its own label, so the browser can autofill it and dictation and screen readers can address it; how each assistive technology does so is recorded in the AT test record as it is tested. The one-field alternative, aTextInputwithmasks.date(), is preferred for most dates; the boxes stay supported. - Deviations: none from APG. One deviation from the keyboard practice, approved by the maintainer: focus moves to the next box when the user's typing fills a box (auto-advance), on by default,
autoAdvance={false}turns it off. The practice says typing never moves focus (3.2.2 On Input (A)), so six guards and a visible hint make it predictable, and DateInput is the only exception (OneTimeCode, TextInput and every other control keep "typing never moves focus"). Decisions: three native text inputs, nevertype="date"; the order follows the region throughIntland a month-first result becomes day first; three Tab stops, no arrow-key stepping; the consumer writes the date example;Fieldset.Root'sinvaliddoes not cascade, each box has its owninvalid. - Native elements used:
<fieldset>and<legend>(the consumer'sFieldset.RootandFieldset.Legend),<div>(DateInput.Root, and one per box),<label for>(the box label),<input type="text">withinputmode="numeric"(the boxes).
A DateInput is one question ("Date of birth") answered with three boxes: day, month and year. DateInput.Root renders the row of boxes and goes inside a Fieldset.Root, whose legend is the question and names the group. Each box is a Field with a visible label ("Day", "Month", "Year") and a native TextInput. It holds no form state: the value is the value prop and each change is reported up, or the native inputs keep it and a form submit reads it. It never parses or validates the date: that is the form's job.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
The group (Fieldset.Root) | <fieldset> → group | Named by its <legend>. aria-describedby = description and help text ids in DOM order, then the error id (see Fieldset) | The consumer renders it. Write group: the boxes never carry the optional marker ("(optional)" in English; DateInput.Root drops it), so only a group Fieldset puts it on the legend of an optional date. required removes it |
| DateInput.Root | <div>, no role, then a <p> (the auto-advance hint) | none on the row. The hint is one of the group's descriptions (aria-describedby). data-* none | Class kv-date-input. Props: name, value, defaultValue, onValueChange, autoComplete, required, disabled, readOnly, autoAdvance, invalidParts, messages, and every div prop. Without children it renders Day, Month and Year in the locale's order. required and disabled default to the Fieldset's. Warns when it is not inside a group. The hint <p class="kv-field-help-text"> sits right after the row and exists only while autoAdvance is on |
| DateInput.Day, .Month, .Year | <div class="kv-field"> with label + input | The input is a textbox named by its visible label (dateInput.day, .month, .year). aria-invalid="true" only when this box is invalid. aria-required="true" when the group is required. Native disabled, readOnly, data-* | Classes kv-field kv-date-input-day (-month, -year) on the Field, kv-input on the input. inputmode="numeric", spellcheck="false", autocomplete="bday-day" (-month, -year) when the Root has autoComplete="bday". No native maxlength, no pattern, no placeholder. Typed text that would go past the box's length (2, 2, 4) is refused in beforeinput; a paste is never cut, which matters when the date is part of signing in (3.3.8 Accessible Authentication (Minimum) (AA)). The label never has "(optional)" |
useDateInput | the logic, for your own elements | returns order, labels, autoAdvanceHint, rootProps, getBoxProps(part), getInputProps(part) | Options: name, value, defaultValue, onValueChange, autoComplete, readOnly, autoAdvance, messages. order is the locale's, from Intl, and there is no option to replace it. autoAdvanceHint is the message while autoAdvance is on, else undefined: render it and list its id in the group's description yourself |
Rules:
- Three boxes in a named group. In a
Fieldset.Rootwith aFieldset.Legend, the group is named by the legend and each box by its own label. - The group describes the whole date. The auto-advance hint, the
Fieldset.HelpText(the format example) and theFieldset.ErrorMessageare in the fieldset'saria-describedby, in DOM order, not in the boxes'. - Auto-advance (approved by the maintainer). On by default;
autoAdvance={false}is the opt-out. These six guards are what make it acceptable under 3.2.2 On Input (A), and each is tested: 1. Only the user's typing that fills a box, and never from the last box. The input type isinsertTextand the box was shorter before the key; full is two digits for day and month, four for year, and digits only. The next box is the next one in the DOM, which is the Tab order. 2. Never on paste, drop, autofill, deletion, a prefilled or controlled value change, text that is not digits, or the edit of a box that was already full. 3. Forward only. Backspace and Delete edit the box and never move focus, not even in an empty box; Tab and Shift+Tab are native. 4. Users are told before they type (3.2.2 On Input (A)). A visible hint,dateInput.autoAdvanceHint(all five locales, overridable per provider and per instance), sits under the boxes and is in the group'saria-describedby. It exists only whileautoAdvanceis on, and it is not hidden. 5.autoAdvance={false}is the opt-out, for teams that follow the stricter reading: typing never moves focus and the hint is gone.useDateInputhas the same option and returnsautoAdvanceHint. 6. The next box is selected, so typing replaces a prefilled value. - The field order follows the region.
Intl.DateTimeFormat(locale).formatToPartsgives the order. A result that starts with the month (en,en-US) becomes day, month, year, because month first reads as day first for the EU readers this library serves. WritingDateInput.Day,.Monthand.Yearas children in your own order overrides it. invalidis per box. The Fieldset'sinvalidmarks the group's parts only (see Fieldset). A box withinvalid(or named ininvalidParts) getsaria-invalid="true"anddata-invalidon its input, label and Field; the others stay valid. The group's one error is the message.nameis a prefix.name="birth"gives the boxesbirth-day,birth-monthandbirth-year, which a plain form submit sends. Anameon one box wins.- Controlled by
value.value={{ year, month, day }}(all strings) sets the three boxes, and each change callsonValueChange({ year, month, day }, { reason: 'input', part, event })with the whole date as the boxes show it. Nothing is stored. - Uncontrolled without
value.defaultValue(any of the three) sets the starting text; the browser keeps it, andonValueChangestill reports the whole date. - Never parsed, never fixed. Leading zeros, letters and impossible dates stay as typed; the value is strings.
autoComplete="bday"on the Root gives the boxes the tokensbday-day,bday-monthandbday-year(1.3.5 Identify Input Purpose (AA)).- Required and disabled come from the Fieldset when the Root doesn't set them:
requiredmakes every boxaria-requiredanddisableddisables them natively. - Strings are
dateInput.day,dateInput.month,dateInput.yearanddateInput.autoAdvanceHint, from the provider, the instancemessagesor the built-in English, in at least sv and en. - No axe violations in the default, invalid, disabled and read-only states.
- Dev warnings: a Root outside any group; a Day, Month or Year outside a Root; a Root in a Fieldset that is neither
groupnorrequired, where an optional date would say so nowhere. - The optional marker is the legend's. In a
groupFieldset that isn'trequired, the legend ends with "(optional)", and no box does, also when the Fieldset is neithergroupnorrequired.
It announces nothing.
What you need to do#
- Leave
autoAdvanceon unless your service follows the stricter reading of 3.2.2 On Input (A). Never hide the hint: it is the advance notice (3.2.2). With the hook, renderautoAdvanceHintas visible text and list its id in the group'saria-describedby. - A
Fieldset.Rootaround the DateInput, with aFieldset.Legendthat asks the question ("Date of birth"), first in the fieldset. The legend ends with "(optional)" in agroupfieldset that isn'trequired. - A native
<fieldset>gets no dev warning and no marker for an optional date, so you write "(optional)" in the legend yourself, in your own language. - A
Fieldset.HelpTextwith an example in the field order ("For example 2007 3 27" when the order is year, month, day, "For example 27 3 2007" when it is day, month, year), under the boxes. KvirnUI supplies no example text: it names the fields, and the example is the service's (3.3.2 Labels or Instructions (A)). Write it in the order the boxes are in. - One message for the whole date in
Fieldset.ErrorMessage, after the boxes, andinvalidon the wrong boxes only ("must include a year" marks Year, "must be a real date" marks all three). Say what is wrong and how to fix it (3.3.1 Error Identification (A), 3.3.3 Error Suggestion (AA)). - Pass
valueandonValueChangefrom your form state, ordefaultValueandnamefor a plain<form>. Validate the date yourself: DateInput never parses it. - Carry forward a date the user already gave earlier in the same process, with
valueordefaultValue, so they don't enter it again (3.3.7 Redundant Entry (A)). - A date of birth gets
autoComplete="bday". Don't set it on other dates (1.3.5 Identify Input Purpose (AA)). - Pick the order from the page's locale, or deliberately override it when the service must match a paper form. Then the help text follows the order.
- For a date to pick near today, add a DatePicker button after the boxes: typing still works there. Don't use a DateInput for a date nobody knows by heart.
Warning: Don't forget
Ask the question in the legend and write an example under the boxes, in the order the boxes are in. Without a legend the three boxes have no shared question (1.3.1 Info and Relationships). Without an example the format is unclear (3.3.2 Labels or Instructions).
Visual and modes#
- Focus indicator: the TextInput's own, a ring at least 2 pixels thick with at least 3:1 contrast against its surroundings (2.4.13 Focus Appearance, AAA), on the focused box.
- Target size: each box is as high as a TextInput and wide enough for its digits, above the 24 by 24 pixel minimum of 2.5.8 Target Size (Minimum) (AA), also in the compact density. The year box is wider than day and month.
- Colour: an invalid box takes the TextInput's invalid state, a thicker edge in the error colour with no shift of the text, plus the group's message (never colour alone, 1.4.1 Use of Color (A)). A disabled box has a dashed edge; a read-only box has a solid edge.
- Forced colours (a user's high-contrast mode): the TextInput's system colours; every box keeps a visible edge and the message stays visible (the
storybook-forced-colorssweep runs every story with forced colours on: axe and the visible-boundary and focus-ring checks pass). That an invalid box's edge is thicker than a valid one's is not asserted by a sweep: it is reviewed by eye and in Windows Contrast Themes. - Reduced motion: no motion of its own.
- Right to left: the boxes flow right to left in the order of the page, and digits stay left to right.
Warning: Don't forget
If you restyle the boxes, keep a visible focus ring (2.4.7 Focus Visible), keep each box at least 24 CSS pixels high (2.5.8 Target Size (Minimum)), and show a wrong box by more than colour (1.4.1 Use of Color).
Focus management#
- Initial focus: not moved.
- Focus moves on its own in one case: the auto-advance (Keyboard above). It moves forward to the next box in the DOM, never back, never out of the date, and never to a disabled box.
- Trap: no.
- Restore to: not applicable.
- On error: DateInput never moves focus. The consumer moves it, to the first invalid box, or to the first box when the whole date is wrong.
- Never obscured by: nothing around the boxes clips the focus ring.
Warning: Don't forget
DateInput never moves focus after an error, so you do. After a failed submit, move focus to the first wrong box, or to the first box when the whole date is wrong. That takes the user to the problem.
WCAG success criteria#
- 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A): a fieldset with a legend, a visible label for each box.
- 1.3.5 Identify Input Purpose (AA):
autocomplete="bday-day",bday-monthandbday-year. - 1.4.1 Use of Color (A), 1.4.11 Non-text Contrast (AA): the invalid edge's width and the message.
- 2.1.1 Keyboard (A), 2.4.3 Focus Order (A): three Tab stops in the field order, native keys. Auto-advance moves forward in that same order.
- 2.4.7 Focus Visible (AA), 2.4.11 Focus Not Obscured (Minimum) (AA). 2.4.13 Focus Appearance is AAA and is not counted toward the AA bar.
- 2.5.3 Label in Name (A), 2.5.8 Target Size (Minimum) (AA): a story checks the size of each box, also in the compact density.
- 3.2.2 On Input (A): auto-advance is not a change of context in the usual reading (the user stays in the same date, in the next of its boxes), and it is advised before the user types (the visible hint in the group's description), forward only, and off with
autoAdvance={false}. The maintainer accepted this trade-off. W3C's own explanation of 3.2.2 gives moving focus on to the next field of a phone number as an example that is acceptable when it is described to the user. - 3.3.1 Error Identification (A), 3.3.2 Labels or Instructions (A), 3.3.3 Error Suggestion (AA): the legend asks, the help text gives the format in the field order, the error says what to do.
- 3.3.7 Redundant Entry (A):
valueordefaultValuecarries a date the user already gave forward; carrying it forward is the consumer's. - 3.3.8 Accessible Authentication (Minimum) (AA): if the date is part of an authentication step, paste is never cut and
autoComplete="bday"autofill works, so it doesn't block a password manager or the browser.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
All native, with one addition: DateInput handles no keys and never calls preventDefault on one, but typing the digit that fills a box moves focus to the next box (auto-advance, on by default, autoAdvance={false} turns it off). That deviates from the keyboard practice's "typing never moves focus" (3.2.2 On Input (A)), and the maintainer approved it for DateInput only, because a date is three short, fixed-length boxes and typing it without Tab is what people expect. The guards are in "Rules" above: forward only, never on paste, deletion, autofill or a changed value, never from the last box, a visible hint tells users before they type, and the next box's text is selected. The group is three Tab stops, one per box, in the field order, because each box is its own text input (the date is not a composite widget), and the arrow keys never step a value up or down (numbers are text). The legend, hint, labels and error are not Tab stops. Which box comes first depends on the locale (day first, or year first for sv-SE), and the table says "first" and "last" in that order. In right-to-left text the boxes flow right to left in DOM order, and Tab follows the DOM.
| Key | Where | What happens |
|---|---|---|
| Tab | before the date | Moves focus to the first box in the field order Test: date-input.test.tsx › Tab enters the date at the first box of the field order |
| Tab | on a box | Moves focus to the next box in the field order. From the last box it leaves the date, to the next focusable element Test: date-input.test.tsx › Tab moves from box to box in the field order and leaves after the last, date-input.test.tsx › right to left: Tab follows the DOM order and the arrow keys stay in the box |
| Shift+Tab | on a box | Moves focus to the previous box. From the first box it leaves the date, to the previous focusable element Test: date-input.test.tsx › Shift+Tab moves back through the boxes and leaves before the first |
| Digit | on a box, and the digit fills it (two for day and month, four for year) | Types it, and moves focus to the next box in the field order with its text selected. A box that is not full, or a text that is not digits, keeps focus Test: date-input.test.tsx › typing the last digit of a box moves focus to the next box: year, month, day for sv-SE, and never from the last, date-input.test.tsx › moving focus selects the whole next box, so typing replaces a prefilled value |
| Characters | on the last box, or a box that does not fill | Types them up to the box's length (2, 2, 4): a key past it is refused, in beforeinput, and a paste is never cut. Focus stays: there is no box after the last, and letters never fill a boxTest: date-input.test.tsx › a box that is not full, and text that is not digits, never advance, date-input.test.tsx › a box takes only its own number of digits when typed in, and a paste is never cut |
| Characters | on a box that was already full | Types them. Focus stays: an edit of a full box never advances Test: date-input.test.tsx › an edit of a box that was already full never advances |
| Backspace / Delete | on a box, also an empty one | Edit the box. Focus never moves, not even back from an empty box (Shift+Tab goes back) Test: date-input.test.tsx › Backspace and Delete never move focus, not even in an empty box |
| Digit | on a box, with autoAdvance={false} | Types it. Focus never moves to the next box, and there is no hint Test: date-input.test.tsx › autoAdvance={false}: typing never moves focus, and the hint is gone |
| ArrowUp / ArrowDown | on a box | Do not change the value. A number is text here: the keys only move the caret, as in any text field Test: date-input.test.tsx › ArrowUp and ArrowDown never step the value |
| ArrowLeft / ArrowRight / Home / End | on a box | Move the caret inside the box (flips in RTL: the browser's own). They never move focus to another box Test: date-input.test.tsx › ArrowLeft, ArrowRight, Home and End move the caret and never leave the box |
| Enter | on a box, in a form | Submits the form (native). DateInput does not intercept it Test: date-input.test.tsx › Enter in a box submits the form |
API reference#
import { DateInput, Fieldset, useDateInput } from '@kvirn-ui/react'DateInput.Root
Renders A <div> with no role that holds the boxes. While autoAdvance is on, a <p> with the hint follows it. It takes every attribute of a <div> and passes ref to the div. Put it inside a Fieldset.Root with a Fieldset.Legend. Without children it renders Day, Month and Year in the locale’s order. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | – | A prefix for the boxes’ name: "birth" gives birth-day, birth-month and birth-year. Without it a form submit sends nothing. |
value | DateInputValue | – | Controlled: { year, month, day }, all strings ("" for an empty box). Pair it with onValueChange. |
defaultValue | Partial<DateInputValue> | – | Uncontrolled: the text each box starts with. The native inputs keep it after that. |
onValueChange | (value: DateInputValue, details: DateInputChangeDetails) => void | – | Called with the whole date, as typed, after every change in any box. details is { reason: "input", part, event }. It only reports and never parses. |
autoComplete | 'bday' | – | For a date of birth only: the boxes get bday-day, bday-month and bday-year (1.3.5). |
required | boolean | The Fieldset’s | aria-required on the three boxes. |
disabled | boolean | The Fieldset’s | Native disabled on the three boxes. |
readOnly | boolean | false | Native readOnly on the three boxes. |
autoAdvance | boolean | true | Focus moves to the next box, with its text selected, when the user’s typing fills a box. Turns the visible hint under the boxes on. false turns both off: typing never moves focus. |
invalidParts | readonly DateInputPart[] | – | The wrong boxes: aria-invalid and data-invalid on those only. With your own children, set invalid on each box instead. |
messages | Partial<KvirnMessages['dateInput']> | – | Replaces the three labels and the auto-advance hint for this date. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-date-input | always | The part class: the row of boxes. The default theme styles it. |
kv-field-help-text | on the hint | The auto-advance hint is a paragraph with this class, right after the row, while autoAdvance is on. It is part of the Fieldset’s description. |
DateInput.Day
Renders A <div class="kv-field"> with a visible label (dateInput.day) and a text <input>. It takes the props of a TextInput except type, value, defaultValue, onValueChange, mask, announceRejections, messages and part: the Root gives it its name, value, autocomplete and read-only state. The props and ref go to the input.
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | boolean | In invalidParts, else false | This box is wrong: aria-invalid and data-invalid on its input, label and field. The Fieldset’s invalid marks none of the boxes. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-date-input-day | on the box’s Field | Next to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise. |
kv-input | on the input | The text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern. |
data-invalid | present or absent | On the input, its label and its field when this box is invalid. |
aria-invalid | "true" or absent | On the input when this box is invalid. Set invalid, not this. |
data-required | present or absent | On the input, its label and its field when the Fieldset or the Root is required. |
data-disabled | present or absent | On the input, its label and its field when the Fieldset or the Root is disabled. |
autocomplete | "bday-day", "bday-month", "bday-year" or absent | Set when the Root has autoComplete="bday". |
DateInput.Month
Renders A <div class="kv-field"> with a visible label (dateInput.month) and a text <input>. It takes the props of a TextInput except type, value, defaultValue, onValueChange, mask, announceRejections, messages and part: the Root gives it its name, value, autocomplete and read-only state. The props and ref go to the input.
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | boolean | In invalidParts, else false | This box is wrong: aria-invalid and data-invalid on its input, label and field. The Fieldset’s invalid marks none of the boxes. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-date-input-day | on the box’s Field | Next to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise. |
kv-input | on the input | The text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern. |
data-invalid | present or absent | On the input, its label and its field when this box is invalid. |
aria-invalid | "true" or absent | On the input when this box is invalid. Set invalid, not this. |
data-required | present or absent | On the input, its label and its field when the Fieldset or the Root is required. |
data-disabled | present or absent | On the input, its label and its field when the Fieldset or the Root is disabled. |
autocomplete | "bday-day", "bday-month", "bday-year" or absent | Set when the Root has autoComplete="bday". |
DateInput.Year
Renders A <div class="kv-field"> with a visible label (dateInput.year) and a text <input>. It takes the props of a TextInput except type, value, defaultValue, onValueChange, mask, announceRejections, messages and part: the Root gives it its name, value, autocomplete and read-only state. The props and ref go to the input.
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | boolean | In invalidParts, else false | This box is wrong: aria-invalid and data-invalid on its input, label and field. The Fieldset’s invalid marks none of the boxes. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-date-input-day | on the box’s Field | Next to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise. |
kv-input | on the input | The text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern. |
data-invalid | present or absent | On the input, its label and its field when this box is invalid. |
aria-invalid | "true" or absent | On the input when this box is invalid. Set invalid, not this. |
data-required | present or absent | On the input, its label and its field when the Fieldset or the Root is required. |
data-disabled | present or absent | On the input, its label and its field when the Fieldset or the Root is disabled. |
autocomplete | "bday-day", "bday-month", "bday-year" or absent | Set when the Root has autoComplete="bday". |
useDateInput
Options
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | – | A prefix for the three inputs’ name. |
value | DateInputValue | – | Controlled: all three as strings. |
defaultValue | Partial<DateInputValue> | – | Uncontrolled: the text each box starts with. |
onValueChange | (value: DateInputValue, details: DateInputChangeDetails) => void | – | Called with the whole date after every change. It only reports. |
autoComplete | 'bday' | – | For a date of birth: bday-day, bday-month and bday-year. |
readOnly | boolean | false | Native readOnly on the inputs. |
autoAdvance | boolean | true | Move focus to the next box when typing fills one. Render autoAdvanceHint while it is on. |
messages | Partial<KvirnMessages['dateInput']> | – | Replaces the labels and the hint. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
order | readonly DateInputPart[] | – | The order of the boxes: year, month, day for sv-SE; day, month, year for sv-FI, fi, nb and en. Read it to write the example in the help text. |
labels | Record<DateInputPart, string> | – | The resolved labels of the three boxes. |
autoAdvanceHint | string | undefined | – | The hint while autoAdvance is on, undefined when it is off. Render it as visible text in the group’s description. |
rootProps | DateInputRootPartProps | – | Spread on the row: the class kv-date-input. |
getBoxProps | (part) => DateInputBoxPartProps | – | Spread on a box’s Field.Root: the class kv-date-input-<part>. |
getInputProps | (part) => DateInputInputPartProps | – | Spread on a box’s input: name, inputMode, spellCheck, autoComplete, value or defaultValue, readOnly, onChange and the ref the hook needs. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one DateInput, pass its messages prop.
dateInput.day
The visible label of the Day box.
| Language | Default text |
|---|---|
| Svenska | Dag |
| Suomi | Päivä |
| Norsk bokmål | Dag |
| Norsk nynorsk | Dag |
| English | Day |
dateInput.month
The visible label of the Month box.
| Language | Default text |
|---|---|
| Svenska | Månad |
| Suomi | Kuukausi |
| Norsk bokmål | Måned |
| Norsk nynorsk | Månad |
| English | Month |
dateInput.year
The visible label of the Year box.
| Language | Default text |
|---|---|
| Svenska | År |
| Suomi | Vuosi |
| Norsk bokmål | År |
| Norsk nynorsk | År |
| English | Year |
dateInput.autoAdvanceHint
The hint under the boxes that says focus moves on when a box is full.
| Language | Default text |
|---|---|
| Svenska | Fokus flyttas till nästa ruta när en ruta är full. |
| Suomi | Kohdistus siirtyy seuraavaan kenttään, kun kenttä on täynnä. |
| Norsk bokmål | Fokus flyttes til neste felt når et felt er fullt. |
| Norsk nynorsk | Fokus blir flytta til neste felt når eit felt er fullt. |
| English | Focus moves to the next box when a box is full. |
Known issues#
aria-describedbyon a<fieldset>isn't announced consistently by TalkBack. See the Fieldset page.- An invalid box isn't linked to the group's error. The box has
aria-invalid="true", and the error is in the fieldset's description, which screen readers read on entering the group. A box added to the error's description would repeat it three times. - A year with fewer than four digits (
0999) always needs Tab: the box is never full. - A controlled parent that rejects a keystroke still sees focus move when the box would have been full: the advance reads the typed text, not the value React keeps.
- Pasting a whole date ("27.3.2007") into one box isn't split across the three. It is out of scope.
Information: Did you know?
Anything on this list that your users may meet belongs in your accessibility statement, with its workaround.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | date-input.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | date-input.test.tsx (axe and role, name and state): has no axe violations in every state, the group is named by its legend and each box by its label |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 11 rows, each names a test in date-input.test.tsx |
| Focus order and management | pass | n/a | pass | date-input.test.tsx: typing the last digit of a box moves focus to the next box: year, month, day for sv-SE, and never from the last |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
Research questions for the AT run: do NVDA, JAWS, VoiceOver and TalkBack users who type fast notice the auto-advance (the label is read on arrival), and do they hear the hint on entering the group? Does dictating digits ("one nine nine zero") behave? Do NVDA, JAWS and VoiceOver announce the group name and its hint on the first box? Is the group's error read on entering the group when only one box is marked invalid, or does the box need its own link to the error? Do Swedish residents (year first) and Finland-Swedish residents (day first) both complete the date without errors in their own order?
What to check#
With a screen reader and the keyboard, try:
- Tab into the first box: the legend, "group", the hint, the example and then the box label are read.
- Two digits in Day move focus to Month with its text selected. Check that the move is noticeable when typing fast.
- A letter, a paste, or Backspace in an empty box does not move focus. Shift+Tab goes back.
- With only the year wrong, the error is read on entering the group and Year is marked invalid.
- Autofilling a date of birth fills all three boxes. Dictating digits into one box works.