When to use it#
- Use it as an add-on to a date field, a DateInput or one TextInput with a date mask, when the date is near today and easier to pick than to type: a booking, a visit, a start date.
- Use it in forms for residents and for staff. You keep the form state: the picker takes the field’s date and gives back the chosen day.
- Not for a start and an end: use DateRangePicker.
- Not for a date the user knows by heart, such as a date of birth: use DateInput alone.
- Not as a section of the page: use a Calendar beside the field.
Example#
import {
DateInput,
DatePicker,
Fieldset,
dateInputValueToIsoDate,
isoDateToDateInputValue,
useDateInput,
} from '@kvirn-ui/react'
import type { DateInputValue } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDatePickerTexts } from './texts.ts'
const boxes = { day: DateInput.Day, month: DateInput.Month, year: DateInput.Year }
export function VisitDate() {
const { texts } = useDatePickerTexts()
const { order } = useDateInput()
const [date, setDate] = useState<DateInputValue>({ year: '', month: '', day: '' })
return (
<div>
<DatePicker.Root
value={dateInputValueToIsoDate(date)}
onValueChange={(isoDate) => setDate(isoDateToDateInputValue(isoDate))}
>
<Fieldset.Root group required>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<DateInput.Root name="visit" value={date} onValueChange={setDate}>
{order.map((part) => {
const Box = boxes[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>
</div>
)
}Use cases#
One field with a date mask
A single TextInput with masks.date() is the shortest field. Put it and the trigger in a div with the class kv-date-picker-row, so the trigger sits beside it and wraps below it on a narrow screen. Turn the text into an ISO date for the picker with maskedDateToIsoDate, and the chosen day back into the text with isoDateToMaskedDate.
For example 27/10/2026
import {
DatePicker,
Field,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDatePickerTexts } from './texts.ts'
export function MaskedVisitDate() {
const { texts } = useDatePickerTexts()
const { locale } = useLocale()
const [fieldText, setFieldText] = useState('')
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<div>
<DatePicker.Root
value={maskedDateToIsoDate(fieldText, locale)}
onValueChange={(isoDate) => setFieldText(isoDateToMaskedDate(isoDate, locale))}
>
<Field.Root>
<Field.Label>{texts.fieldLabel}</Field.Label>
<div className="kv-date-picker-row">
<TextInput
name="visit"
mask={masks.date()}
value={fieldText}
onValueChange={setFieldText}
/>
<DatePicker.Trigger />
</div>
<Field.HelpText>{texts.fieldHint(example)}</Field.HelpText>
</Field.Root>
<DatePicker.Popup />
</DatePicker.Root>
</div>
)
}Props in this example:
valueon DatePicker.RootonValueChangeon DatePicker.Root
Only some dates can be chosen
Set minimum and maximum. The dialog writes them in words above the grid. Say them in the field’s help text too, because people read that text first. The example checks a typed date against the same limits and shows an error. It fixes today, so the dates are the same on any day.
You can choose a date from 14 October to 31 December 2026.
import {
DatePicker,
Field,
TextInput,
checks,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDatePickerTexts } from './texts.ts'
const earliest = '2026-10-14'
const latest = '2026-12-31'
export function LimitedVisitDate() {
const { texts } = useDatePickerTexts()
const { locale } = useLocale()
const [fieldText, setFieldText] = useState('')
const typedDate = maskedDateToIsoDate(fieldText, locale)
const isOutside =
typedDate !== '' && checks.date(typedDate, { min: earliest, max: latest }).reason === 'range'
return (
<div>
<DatePicker.Root
today={earliest}
minimum={earliest}
maximum={latest}
value={typedDate}
onValueChange={(isoDate) => setFieldText(isoDateToMaskedDate(isoDate, locale))}
>
<Field.Root invalid={isOutside}>
<Field.Label>{texts.fieldLabel}</Field.Label>
<div className="kv-date-picker-row">
<TextInput
name="visit"
mask={masks.date()}
value={fieldText}
onValueChange={setFieldText}
/>
<DatePicker.Trigger />
</div>
<Field.HelpText>{texts.window}</Field.HelpText>
<Field.ErrorMessage>{isOutside ? texts.outsideError : ''}</Field.ErrorMessage>
</Field.Root>
<DatePicker.Popup />
</DatePicker.Root>
</div>
)
}Props in this example:
Warning: Don't forget
The picker never checks what is typed. Check the typed date against the same limits in your form, for example with checks.date and its min and max, and say how to fix it (3.3.1 Error Identification).
Days that are closed, with the reason
A day that can’t be chosen stays reachable with the keyboard and is struck through. The reason is part of its name, so a screen reader reads it. Most people look at the typed field first, so write the closed days in its help text, and show an error when someone types a closed date.
We’re closed on October 16, October 17, and October 24.
import {
DatePicker,
Field,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useFormat,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDatePickerTexts } from './texts.ts'
const closedDays = ['2026-10-16', '2026-10-17', '2026-10-24']
export function ClosedVisitDays() {
const { texts } = useDatePickerTexts()
const { locale } = useLocale()
const format = useFormat()
const [fieldText, setFieldText] = useState('')
const typedDate = maskedDateToIsoDate(fieldText, locale)
const isClosed = closedDays.includes(typedDate)
const shortDate = (date: string) => format.date(date, { day: 'numeric', month: 'long' })
const closedError = isClosed ? texts.closedError(shortDate(typedDate)) : ''
return (
<div>
<DatePicker.Root
today="2026-10-14"
isDateUnavailable={(date) => closedDays.includes(date)}
getDateDescription={(date) => (closedDays.includes(date) ? texts.closed : undefined)}
value={typedDate}
onValueChange={(isoDate) => setFieldText(isoDateToMaskedDate(isoDate, locale))}
>
<Field.Root invalid={isClosed}>
<Field.Label>{texts.fieldLabel}</Field.Label>
<div className="kv-date-picker-row">
<TextInput
name="visit"
mask={masks.date()}
value={fieldText}
onValueChange={setFieldText}
/>
<DatePicker.Trigger />
</div>
<Field.HelpText>
{texts.closedHint(format.list(closedDays.map(shortDate)))}
</Field.HelpText>
<Field.ErrorMessage>{closedError}</Field.ErrorMessage>
</Field.Root>
<DatePicker.Popup />
</DatePicker.Root>
</div>
)
}Props in this example:
isDateUnavailableon DatePicker.RootgetDateDescriptionon DatePicker.Root
Naming the dialog after the question
The default title says “Choose a date”. A title that repeats the field’s question tells the user which date they are choosing.
For example 27/10/2026
import {
DatePicker,
Field,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDatePickerTexts } from './texts.ts'
export function TitledVisitDate() {
const { texts } = useDatePickerTexts()
const { locale } = useLocale()
const example = masks.date().withLocale(locale).format('2026-10-27')
const [fieldText, setFieldText] = useState('')
return (
<div>
<DatePicker.Root
messages={{ title: texts.title }}
value={maskedDateToIsoDate(fieldText, locale)}
onValueChange={(isoDate) => setFieldText(isoDateToMaskedDate(isoDate, locale))}
>
<Field.Root>
<Field.Label>{texts.fieldLabel}</Field.Label>
<div className="kv-date-picker-row">
<TextInput
name="visit"
mask={masks.date()}
value={fieldText}
onValueChange={setFieldText}
/>
<DatePicker.Trigger />
</div>
<Field.HelpText>{texts.fieldHint(example)}</Field.HelpText>
</Field.Root>
<DatePicker.Popup />
</DatePicker.Root>
</div>
)
}Props in this example:
messageson DatePicker.Root
Information: Did you know?
To change the text for your whole app, pass messages to KvirnProvider instead.
Accessibility#
What it does for you#
- APG pattern: Date Picker Dialog (a modal dialog around a grid), after a typed field. The grid is described on the Calendar page; the dialog on the Dialog page.
- Deviations: none new. From the APG example: no OK and Cancel buttons (Enter selects, Close and Escape cancel); the month is announced by Announcer on a button press, not by a live heading (as in Calendar); Tab leaves the modal to the browser's own UI before wrapping (a deviation from the APG Dialog pattern, approved).
- Native elements used:
<button type="button">(trigger and Close), a native<dialog>shown withshowModal(),<h2>(title), and the Calendar's<table role="grid">.
DatePicker is an add-on to a typed field (a DateInput, or one masks.date() TextInput): typing always works, and the dialog is the slower path for keyboard and screen reader users. It is controlled only: it keeps no date of its own. The field's date goes in as value (as year-month-day, such as 2026-10-15), and the chosen day comes out through onValueChange for the consumer to write into the field. It chooses one date. For a start and an end, use DateRangePicker.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Root | none (renders no element) | none | Owns the open state, the range and the Dialog's context |
| Trigger | <button type="button"> → button | name = its visible text datePicker.trigger; aria-haspopup="dialog"; aria-expanded true/false | The calendar icon is decorative (aria-hidden). Classes kv-button kv-date-picker-trigger; data-open while open. Last item in the DateInput row |
| Popup | native <dialog> → dialog | aria-modal="true" while open; aria-labelledby → Title | Class kv-dialog kv-date-picker-popup. Top layer; the page behind is inert |
| Title | <h2> (tabindex="-1") | none | datePicker.title, replaceable with the question. Names the dialog |
| Close | <button> icon button | name = dialog.close | The Dialog's own Close |
| Calendar | div.kv-calendar with the Calendar's parts | as on the Calendar page | Mounted only while the dialog is open, so it reads the typed date and today afresh each time. aria-selected on the typed date |
Rules the automated tests check:
- Opens on the selected (typed) date when the field holds a real date, else on today; a date outside
minimum–maximumopens on the nearest day inside it. A partial or impossible date gives no error from the picker: the form validates withchecks.date. - Choosing an available day closes the dialog at once, calls
onValueChangewith the ISO date, and the consumer writes it into the boxes without leading zeros (isoDateToDateInputValue) or into the masked field (isoDateToMaskedDate). An unavailable day does nothing and the dialog stays open. - Dev warnings (once): a
valuethat is not in the form year-month-day; a part used outside a DatePicker.Root.
What you need to do#
- Keep the typed field. DatePicker never replaces it: typing always works, and it avoids dragging (2.5.7 Dragging Movements (AA)). Where the typed field collects information about the user, such as a date of birth, give it the matching
autocompletevalue yourself (1.3.5 Identify Input Purpose (AA)). A DateInput stays in aFieldsetwith a legend, help text with an example, and an error. - Bridge the value.
value={dateInputValueToIsoDate(boxes)}(ormaskedDateToIsoDate(text, locale)) in, andonValueChange={(date) => setBoxes(isoDateToDateInputValue(date))}out. Validate the field yourself (checks.date, with itsrange). - Say the range. Pass
minimumandmaximumand put them in the field's help text too (3.3.2 Labels or Instructions (A)): the dialog's range hint is only visible once it is open. - Name the task. Replace the title with the question ("Choose the day of your visit").
- Put the trigger inside the date's row. The Popup can sit in a page
<form>: none of its buttons submits it. - Not for a date of birth or any date far from today: type it. Not when many days are unavailable: use radio buttons.
- Everything on the Calendar page and the Dialog page applies too.
Warning: Don't forget
Say the dates that can be chosen in the field’s help text too. The dialog’s own line is only visible once the dialog is open (3.3.2 Labels or Instructions).
Visual and modes#
- Focus indicator: the trigger and Close are Buttons, with a ring at least 2 pixels thick and at least 3:1 contrast against its surroundings (2.4.13 Focus Appearance, AAA); the grid's is described on the Calendar page.
- Target size: the trigger is a Button, and the day cells are the Calendar's, which are smaller on a narrow screen so that seven columns fit a 320 pixel screen. All are above the 24 by 24 pixel minimum of 2.5.8 Target Size (Minimum) (AA).
- Layout: the trigger is last in the row of boxes and wraps below them on a 320 pixel screen or at 200% text. On a wide screen the popup is as wide as its calendar, and on a narrow one it is a sheet at the bottom of the screen.
- Forced colours (a user's high-contrast mode): as the Dialog and the Calendar; the trigger is a Button.
- Reduced motion: the Dialog's own open motion only.
Focus management#
- Without a provider
timeZone, "today" is the UTC date on first paint only. The Calendar mounts in the popup on every open, so a popup that opens after mount starts on the browser's date (no switch) and initial focus lands on the cell markedaria-current="date". - Initial focus: the day with the Tab stop (the typed date, else today, kept inside the range), through the Dialog's
initialFocusRef. Not the first month button. - Trap: yes, native modal (the page behind is
inert). Tab leaves to the browser's UI before wrapping (a deviation from the APG Dialog pattern, approved), so there is no keyboard trap (2.1.2 No Keyboard Trap, A). - Restore to: the trigger, for a choice, Escape and Close alike. If the trigger is gone, the first box of the field (the first input in the trigger's nearest
fieldset, group or field). Neverbody. - Never obscured by: nothing inside is sticky; the sheet scrolls (2.4.11 Focus Not Obscured (Minimum) (AA)).
Information: Did you know?
Without a timeZone on KvirnProvider, the first paint uses today’s date in UTC, and a dialog that opens later starts on the browser’s date. Pass timeZone so the server and the browser agree on the day.
WCAG success criteria#
- 2.1.1 Keyboard (A), 2.1.2 No Keyboard Trap (A), 2.4.3 Focus Order (A): every row above; focus lands on the day and returns to the trigger.
- 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A): roles, names and states of the trigger, dialog and grid (checked by tests and axe).
- 3.3.2 Labels or Instructions (A): the range hint and the field's help text. 3.3.7 Redundant Entry (A): the typed date is the starting point. 2.5.7 Dragging Movements (AA): nothing needs dragging.
- 2.4.7 Focus Visible (AA): the trigger, Close and the focused day show a focus ring.
- 1.4.3 Contrast (Minimum) (AA) and 1.4.11 Non-text Contrast (AA): the text, the focus ring and the borders are measured in the default theme.
- 2.4.11 Focus Not Obscured (Minimum) (AA): nothing inside the dialog is sticky.
- 4.1.3 Status Messages (AA):
{date} selectedafter the dialog has closed. - 3.1.2 Language of Parts (AA): the Calendar's
langwhen the browser has no data for the locale. - 1.4.10 Reflow (AA): the reflow sweep checks every story at 320 CSS pixels for sideways scrolling, so the dialog and its grid do not scroll sideways.
- 1.4.12 Text Spacing (AA): the text-spacing sweep applies the wider spacing to every story and fails on a box that clips text. 2.5.8 Target Size (Minimum) (AA): the sizes are checked by eye.
Keyboard#
- Focus
- native for the trigger and the dialog's buttons; roving tabindex in the grid (Calendar)
- Selection follows focus
- no (Enter or Space selects)
- Arrows wrap
- no (they cross months, as in Calendar)
- Shortcuts
- none
The grid's own keys (arrows, Home, End, Page keys, month buttons) are in the Calendar contract and are proved by the Calendar's tests; only what the dialog adds is listed here. A key with Control, Alt or Meta is never taken.
| Key | Where | What happens |
|---|---|---|
| Tab | last box | Moves to the trigger, the last item in the row Test: date-picker.test.tsx › keyboard › Tab moves from the last box to the trigger |
| Shift+Tab | trigger | Moves back to the last box Test: date-picker.test.tsx › keyboard › Shift+Tab moves from the trigger back to the last box |
| Tab / Shift+Tab | open dialog | Close, the month buttons, then the grid as one stop; Shift+Tab goes back; Tab leaves the dialog to the browser's own controls, such as the address bar, before it goes round again Test: date-picker.test.tsx › keyboard › Shift+Tab from the day goes through the month buttons to Close, and Tab goes back |
| Enter | trigger | Opens the dialog; focus on the selected date, else today Test: date-picker.test.tsx › keyboard › Enter on the trigger opens the dialog with focus on today when the field is empty |
| Space | trigger | Opens the dialog, as Enter Test: date-picker.test.tsx › keyboard › Space on the trigger opens the dialog |
| Enter | trigger, typed date | Opens on the typed date, which has aria-selectedTest: date-picker.test.tsx › keyboard › the dialog opens on the typed date when the field holds a real date |
| Enter | trigger, a typed date outside the range | Opens on the nearest day inside the range Test: date-picker.test.tsx › keyboard › a typed date outside the range opens inside it |
| ArrowRight | day | Moves to the next day inside the dialog (the rest as Calendar) Test: date-picker.test.tsx › keyboard › an arrow key moves between days inside the dialog |
| Enter | available day | Chooses it, closes, fills the field, focus to the trigger Test: date-picker.test.tsx › keyboard › Enter on an available day closes the dialog, fills the boxes without leading zeros and returns focus to the trigger |
| Space | available day | The same as Enter Test: date-picker.test.tsx › keyboard › Space on an available day chooses it and closes the dialog |
| Enter | unavailable day | Nothing; the dialog stays open Test: date-picker.test.tsx › keyboard › Enter on an unavailable day does nothing and the dialog stays open |
| Space | unavailable day | Nothing; the dialog stays open Test: calendar.test.tsx › keyboard › Enter and Space on an unavailable day select nothing |
| Escape | open dialog | Closes without choosing; the field is unchanged; focus to the trigger Test: date-picker.test.tsx › keyboard › Escape closes without choosing and returns focus to the trigger |
| Enter / Space | Close | Closes without choosing; focus to the trigger Test: date-picker.test.tsx › keyboard › the Close button closes without choosing and returns focus to the trigger |
A click on a day chooses it the same way. The dialog reopens on a date typed since it closed.
Announcements#
DatePicker tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).
| When | What it says | Message key | Politeness |
|---|---|---|---|
| A day is chosen | Thursday 15 October 2026 selected | calendar.selected | Polite |
| A month button is pressed | Polite |
The text in all five languages
Change the text#
For your whole app, pass messages to KvirnProvider. For one DatePicker, pass its messages prop.
<KvirnProvider messages={{ calendar: { selected: 'Thursday 15 October 2026 selected' } }}>Warning: Don't forget
Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
| Field and trigger | the boxes År (Year), Månad (Month), Dag (Day), then button, Välj datum (Choose date), not expanded | none | date-picker.test.tsx › read aloud › reads the field, then the trigger as a button with a popup that is not expanded |
| Open dialog | dialog, Välj ett datum (Choose a date) → heading → grid, oktober 2026 (October 2026) → the typed day, selected | none | date-picker.test.tsx › read aloud › reads the open dialog by its title, then the grid and the typed day as selected |
| A day chosen | polite: torsdag 15 oktober 2026 vald (Thursday 15 October 2026 selected) | polite | date-picker.test.tsx › read aloud › says "{date} vald" as a polite announcement when a day is chosen |
| Closed with Escape or Close | nothing | none | date-picker.test.tsx › announcements › closing with Escape announces nothing and … › closing with Close announces nothing |
API reference#
import { DatePicker, useDatePicker } from '@kvirn-ui/react'DatePicker.Root
Renders No element. It owns the open state and the limits, and gives the Dialog its context. Put the field, DatePicker.Trigger and DatePicker.Popup inside it. Keep the trigger in the same row as the field. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
value | IsoDate | "" (none) | The date the field holds, as YYYY-MM-DD, or "" for none. Build it with dateInputValueToIsoDate or maskedDateToIsoDate. The picker opens on it when it is a real date, else on today. DatePicker is controlled only: it never writes the field itself. |
onValueChange | (date: IsoDate) => void | – | Called with the day when an available day is chosen. Write it into your field with isoDateToDateInputValue or isoDateToMaskedDate. |
open | boolean | – | Controlled: whether the dialog is open. Pair it with onOpenChange. Without it the picker is uncontrolled and starts closed. |
onOpenChange | (open: boolean, details: DatePickerChangeDetails) => void | – | Called when the dialog opens or closes. details.reason is "trigger-press", "close-press", "escape" or "native-close" (the Dialog’s reasons), or "select" when a day was chosen. |
minimum | IsoDate | – | The first day that can be chosen, as YYYY-MM-DD. |
maximum | IsoDate | – | The last day that can be chosen, as YYYY-MM-DD. |
isDateUnavailable | (date: IsoDate) => boolean | – | A day inside the range that can’t be chosen. It stays focusable, struck through. |
getDateDescription | (date: IsoDate) => string | undefined | – | Words added to a day’s name, such as why it is unavailable. |
weekStart | WeekStart | The provider’s | The first day of the week, 1 (Monday) to 7 (Sunday). Else the provider’s, the locale’s, Monday. |
weekNumbers | boolean | false | ISO week numbers, with a Monday start only. |
today | IsoDate | The clock | Today as YYYY-MM-DD, for tests and examples. Else the clock, read each time the dialog opens. |
messages | Partial<KvirnMessages['datePicker']> | – | Replaces the trigger’s text and the dialog’s title for this picker. |
calendarMessages | Partial<KvirnMessages['calendar']> | – | Replaces the Calendar’s strings for this picker, and "{date} selected", said on the page after the dialog has closed. |
DatePicker.Trigger
Renders A <button type="button"> named “Choose date” (datePicker.trigger) with a decorative calendar icon. It takes every attribute of a <button> and passes ref to it. If you pass children, the visible text must stay its name.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-dialog-trigger kv-button kv-date-picker-trigger | always | The part classes. It looks like a Button. |
aria-haspopup | "dialog" | The button opens a dialog. |
aria-expanded | "true" or "false" | Whether the dialog is open. |
data-open | present or absent | The dialog is open. |
DatePicker.Popup
Renders A modal <dialog>, a Dialog popup. With no children it holds the Title, a Close button and the Calendar, which is mounted only while the dialog is open. It takes every attribute of a <dialog> and passes ref to it.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-dialog kv-date-picker-popup | always | The part classes. The default theme styles them. |
aria-modal | "true" while open | The page behind is inert. |
aria-labelledby | the Title’s id | Names the dialog. Give it a title. |
data-open | present or absent | The dialog is open. |
DatePicker.Title
Renders An <h2> that names the dialog, “Choose a date” (datePicker.title). It takes every attribute of a heading and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'h2' | The element, so the title has the level it needs in the page’s outline. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-dialog-title | always | The part class. |
DatePicker.Calendar
Renders A Calendar.Root with the picker’s value and limits set, and the month buttons, heading, range hint and grid inside it. It takes the attributes of a <div>, not the Calendar’s options: those come from the picker. Give it children to compose your own.
useDatePicker
Takes the same options as DatePicker.Root. Render the Calendar only while isOpen: it reads the date when it mounts.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
value | IsoDate | "" (none) | The date the field holds, as YYYY-MM-DD, or "" for none. Build it with dateInputValueToIsoDate or maskedDateToIsoDate. The picker opens on it when it is a real date, else on today. DatePicker is controlled only: it never writes the field itself. |
onValueChange | (date: IsoDate) => void | – | Called with the day when an available day is chosen. Write it into your field with isoDateToDateInputValue or isoDateToMaskedDate. |
open | boolean | – | Controlled: whether the dialog is open. Pair it with onOpenChange. Without it the picker is uncontrolled and starts closed. |
onOpenChange | (open: boolean, details: DatePickerChangeDetails) => void | – | Called when the dialog opens or closes. details.reason is "trigger-press", "close-press", "escape" or "native-close" (the Dialog’s reasons), or "select" when a day was chosen. |
minimum | IsoDate | – | The first day that can be chosen, as YYYY-MM-DD. |
maximum | IsoDate | – | The last day that can be chosen, as YYYY-MM-DD. |
isDateUnavailable | (date: IsoDate) => boolean | – | A day inside the range that can’t be chosen. It stays focusable, struck through. |
getDateDescription | (date: IsoDate) => string | undefined | – | Words added to a day’s name, such as why it is unavailable. |
weekStart | WeekStart | The provider’s | The first day of the week, 1 (Monday) to 7 (Sunday). Else the provider’s, the locale’s, Monday. |
weekNumbers | boolean | false | ISO week numbers, with a Monday start only. |
today | IsoDate | The clock | Today as YYYY-MM-DD, for tests and examples. Else the clock, read each time the dialog opens. |
messages | Partial<KvirnMessages['datePicker']> | – | Replaces the trigger’s text and the dialog’s title for this picker. |
calendarMessages | Partial<KvirnMessages['calendar']> | – | Replaces the Calendar’s strings for this picker, and "{date} selected", said on the page after the dialog has closed. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Whether the dialog is open. |
triggerProps | DatePickerTriggerPartProps | – | Spread on the <button> that opens the picker. |
popupProps | DatePickerPopupPartProps | – | Spread on the <dialog>. Name it with a title. |
titleProps | DialogTitlePartProps | – | Spread on the title element. Call registerTitle from an effect in it. |
closeProps | DialogClosePartProps | – | Spread on the button inside the popup that closes it. |
registerTitle | () => () => void | – | Call it from an effect in your title element, as for a Dialog. |
calendarProps | DatePickerCalendarOptions | – | The Calendar’s options: spread them on Calendar.Root while the dialog is open. Its own "selected" message is off, because the page says it after the dialog has closed. |
triggerText | string | – | "Choose date": the trigger’s visible text. |
titleText | string | – | "Choose a date": the default title. |
dialog | UseDialogResult & { isShown: boolean } | – | The Dialog behind the picker, for DatePicker.Root. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one DatePicker, pass its messages prop.
datePicker.trigger
The visible text and name of the trigger.
| Language | Default text |
|---|---|
| Svenska | Välj datum |
| Suomi | Valitse päivämäärä |
| Norsk bokmål | Velg dato |
| Norsk nynorsk | Vel dato |
| English | Choose date |
datePicker.title
The default title of the dialog.
| Language | Default text |
|---|---|
| Svenska | Välj ett datum |
| Suomi | Valitse päivämäärä |
| Norsk bokmål | Velg en dato |
| Norsk nynorsk | Vel ein dato |
| English | Choose a date |
Known issues#
- A screen reader may not say "{date} selected" when focus lands on the trigger. Check with your users.
- Children you pass to
DatePicker.Popupstay mounted while the dialog is closed (the default Calendar does not).
Information: Did you know?
If an issue here affects your service, list it 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-picker.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | date-picker.test.tsx (axe and role, name and state): the trigger is a button named by its visible text, with a hidden icon, aria-haspopup and aria-expanded false |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 13 rows, each names a test in date-picker.test.tsx |
| Focus order and management | pass | n/a | pass | date-picker.test.tsx: Enter on the trigger opens the dialog with focus on today when the field is empty |
| 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 |
What to check#
- Tab to the field, then to "Choose date". Press Enter: focus is on the typed date (or today), and the dialog is announced with its title.
- Arrow to another day and press Enter: the dialog closes, the field fills, focus is back on the button, and "{date} selected" is announced.
- Reopen and press Escape: the field is unchanged and focus is on the button.
- With a minimum and maximum: the range sentence is read with the grid. A closed day reads its reason, and Enter does nothing.
- Tab and Shift+Tab inside reach Close and the month buttons, and you can always leave.
- At 400% zoom or 320px, the button wraps below the field and nothing is cut off.