Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

DateInput

A date answered with three text boxes: day, month and year, in the order the region writes dates in. Each box has its own visible label, and the browser can fill in a date of birth. It does not check whether the date is real: that is your form’s job.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

When to use it#

  • Use it for a date the user knows by heart, such as a date of birth. Put it in a Fieldset whose legend asks the question. For a date of birth, set autoComplete="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 with checks.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#

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

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.

Date of your visit (optional)

Focus moves to the next box when a box is full.

For example 27 3 2007

Props in this example:

  • name on 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.

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

Error: The year must have four digits

Props in this example:

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.

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

The form state holds: --

Props in this example:

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.

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

Props in this example:

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:

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.

Date of your visit

Focus moves to the next box when a box is full.

For example 27 3 2007

Choose a date

For example 27/10/2026

Choose a date

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.

Date of birth

You can’t change this date here. It comes from the application.

You can’t change this date here. It comes from the application.

Props in this example:

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.

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

For example 27/10/2026

Props in this example:

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.

Date of birth

Focus moves to the next box when a box is full.

For example 27 3 2007

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.

Date of birth

For example 27 3 2007

Props in this example:

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, a TextInput with masks.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, never type="date"; the order follows the region through Intl and a month-first result becomes day first; three Tab stops, no arrow-key stepping; the consumer writes the date example; Fieldset.Root's invalid does not cascade, each box has its own invalid.
  • Native elements used: <fieldset> and <legend> (the consumer's Fieldset.Root and Fieldset.Legend), <div> (DateInput.Root, and one per box), <label for> (the box label), <input type="text"> with inputmode="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.

PartElement / roleARIA / stateNotes
The group (Fieldset.Root)<fieldset> → groupNamed 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-* noneClass 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 + inputThe 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)"
useDateInputthe logic, for your own elementsreturns 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.Root with a Fieldset.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 the Fieldset.ErrorMessage are in the fieldset's aria-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 is insertText and 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's aria-describedby. It exists only while autoAdvance is 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. useDateInput has the same option and returns autoAdvanceHint. 6. The next box is selected, so typing replaces a prefilled value.
  • The field order follows the region. Intl.DateTimeFormat(locale).formatToParts gives 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. Writing DateInput.Day, .Month and .Year as children in your own order overrides it.
  • invalid is per box. The Fieldset's invalid marks the group's parts only (see Fieldset). A box with invalid (or named in invalidParts) gets aria-invalid="true" and data-invalid on its input, label and Field; the others stay valid. The group's one error is the message.
  • name is a prefix. name="birth" gives the boxes birth-day, birth-month and birth-year, which a plain form submit sends. A name on one box wins.
  • Controlled by value. value={{ year, month, day }} (all strings) sets the three boxes, and each change calls onValueChange({ 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, and onValueChange still 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 tokens bday-day, bday-month and bday-year (1.3.5 Identify Input Purpose (AA)).
  • Required and disabled come from the Fieldset when the Root doesn't set them: required makes every box aria-required and disabled disables them natively.
  • Strings are dateInput.day, dateInput.month, dateInput.year and dateInput.autoAdvanceHint, from the provider, the instance messages or 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 group nor required, where an optional date would say so nowhere.
  • The optional marker is the legend's. In a group Fieldset that isn't required, the legend ends with "(optional)", and no box does, also when the Fieldset is neither group nor required.

It announces nothing.

What you need to do#

  • Leave autoAdvance on 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, render autoAdvanceHint as visible text and list its id in the group's aria-describedby.
  • A Fieldset.Root around the DateInput, with a Fieldset.Legend that asks the question ("Date of birth"), first in the fieldset. The legend ends with "(optional)" in a group fieldset that isn't required.
  • 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.HelpText with 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, and invalid on 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 value and onValueChange from your form state, or defaultValue and name for 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 value or defaultValue, 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-colors sweep 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-month and bday-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): value or defaultValue carries 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.

KeyWhereWhat happens
Tabbefore the dateMoves 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
Tabon a boxMoves 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+Tabon a boxMoves 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
Digiton 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
Characterson the last box, or a box that does not fillTypes 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 box
Test: 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
Characterson a box that was already fullTypes 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 / Deleteon a box, also an empty oneEdit 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
Digiton 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 / ArrowDownon a boxDo 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 / Endon a boxMove 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
Enteron a box, in a formSubmits 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.

PropTypeDefaultDescription
namestring–A prefix for the boxes’ name: "birth" gives birth-day, birth-month and birth-year. Without it a form submit sends nothing.
valueDateInputValue–Controlled: { year, month, day }, all strings ("" for an empty box). Pair it with onValueChange.
defaultValuePartial<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).
requiredbooleanThe Fieldset’saria-required on the three boxes.
disabledbooleanThe Fieldset’sNative disabled on the three boxes.
readOnlybooleanfalseNative readOnly on the three boxes.
autoAdvancebooleantrueFocus 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.
invalidPartsreadonly DateInputPart[]–The wrong boxes: aria-invalid and data-invalid on those only. With your own children, set invalid on each box instead.
messagesPartial<KvirnMessages['dateInput']>–Replaces the three labels and the auto-advance hint for this date.
Class or attributeValuesMeaning
kv-date-inputalwaysThe part class: the row of boxes. The default theme styles it.
kv-field-help-texton the hintThe 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.

PropTypeDefaultDescription
invalidbooleanIn invalidParts, else falseThis 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 attributeValuesMeaning
kv-date-input-dayon the box’s FieldNext to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise.
kv-inputon the inputThe text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern.
data-invalidpresent or absentOn the input, its label and its field when this box is invalid.
aria-invalid"true" or absentOn the input when this box is invalid. Set invalid, not this.
data-requiredpresent or absentOn the input, its label and its field when the Fieldset or the Root is required.
data-disabledpresent or absentOn the input, its label and its field when the Fieldset or the Root is disabled.
autocomplete"bday-day", "bday-month", "bday-year" or absentSet 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.

PropTypeDefaultDescription
invalidbooleanIn invalidParts, else falseThis 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 attributeValuesMeaning
kv-date-input-dayon the box’s FieldNext to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise.
kv-inputon the inputThe text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern.
data-invalidpresent or absentOn the input, its label and its field when this box is invalid.
aria-invalid"true" or absentOn the input when this box is invalid. Set invalid, not this.
data-requiredpresent or absentOn the input, its label and its field when the Fieldset or the Root is required.
data-disabledpresent or absentOn the input, its label and its field when the Fieldset or the Root is disabled.
autocomplete"bday-day", "bday-month", "bday-year" or absentSet 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.

PropTypeDefaultDescription
invalidbooleanIn invalidParts, else falseThis 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 attributeValuesMeaning
kv-date-input-dayon the box’s FieldNext to kv-field, so the theme sizes the box. kv-date-input-month and kv-date-input-year likewise.
kv-inputon the inputThe text input’s class. inputmode="numeric", spellcheck="false", no maxlength or pattern.
data-invalidpresent or absentOn the input, its label and its field when this box is invalid.
aria-invalid"true" or absentOn the input when this box is invalid. Set invalid, not this.
data-requiredpresent or absentOn the input, its label and its field when the Fieldset or the Root is required.
data-disabledpresent or absentOn the input, its label and its field when the Fieldset or the Root is disabled.
autocomplete"bday-day", "bday-month", "bday-year" or absentSet when the Root has autoComplete="bday".

useDateInput

Options

PropTypeDefaultDescription
namestring–A prefix for the three inputs’ name.
valueDateInputValue–Controlled: all three as strings.
defaultValuePartial<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.
readOnlybooleanfalseNative readOnly on the inputs.
autoAdvancebooleantrueMove focus to the next box when typing fills one. Render autoAdvanceHint while it is on.
messagesPartial<KvirnMessages['dateInput']>–Replaces the labels and the hint.

Result

PropTypeDefaultDescription
orderreadonly 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.
labelsRecord<DateInputPart, string>–The resolved labels of the three boxes.
autoAdvanceHintstring | undefined–The hint while autoAdvance is on, undefined when it is off. Render it as visible text in the group’s description.
rootPropsDateInputRootPartProps–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.

LanguageDefault text
SvenskaDag
SuomiPäivä
Norsk bokmålDag
Norsk nynorskDag
EnglishDay

dateInput.month

The visible label of the Month box.

LanguageDefault text
SvenskaMånad
SuomiKuukausi
Norsk bokmålMåned
Norsk nynorskMånad
EnglishMonth

dateInput.year

The visible label of the Year box.

LanguageDefault text
SvenskaÅr
SuomiVuosi
Norsk bokmålÅr
Norsk nynorskÅr
EnglishYear

dateInput.autoAdvanceHint

The hint under the boxes that says focus moves on when a box is full.

LanguageDefault text
SvenskaFokus flyttas till nästa ruta när en ruta är full.
SuomiKohdistus siirtyy seuraavaan kenttään, kun kenttä on täynnä.
Norsk bokmålFokus flyttes til neste felt når et felt er fullt.
Norsk nynorskFokus blir flytta til neste felt når eit felt er fullt.
EnglishFocus moves to the next box when a box is full.

Known issues#

  • aria-describedby on 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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassdate-input.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassdate-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)passn/apass11 rows, each names a test in date-input.test.tsx
Focus order and managementpassn/apassdate-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)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

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.