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.

DatePicker

A button next to a date field that opens a calendar in a dialog, so a day can be picked instead of typed. Choosing a day fills in the field. Typing always works: the picker is an extra way to give the date, not a replacement.

Package
@kvirn-ui/react
Pattern
APG Date Picker Dialog
Testing
Automated. Core 0 of 2, Release 0 of 3

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#

Date of your visit

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

For example 27 3 2026

Choose a date

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

Choose a date

Props in this example:

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.

Choose a date

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.

Choose a date

Props in this example:

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

Choose the date of your visit

Props in this example:

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 with showModal(), <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.

PartElement / roleARIANotes
Rootnone (renders no element)noneOwns the open state, the range and the Dialog's context
Trigger<button type="button"> → buttonname = its visible text datePicker.trigger; aria-haspopup="dialog"; aria-expanded true/falseThe calendar icon is decorative (aria-hidden). Classes kv-button kv-date-picker-trigger; data-open while open. Last item in the DateInput row
Popupnative <dialog> → dialogaria-modal="true" while open; aria-labelledby → TitleClass kv-dialog kv-date-picker-popup. Top layer; the page behind is inert
Title<h2> (tabindex="-1")nonedatePicker.title, replaceable with the question. Names the dialog
Close<button> icon buttonname = dialog.closeThe Dialog's own Close
Calendardiv.kv-calendar with the Calendar's partsas on the Calendar pageMounted 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–maximum opens on the nearest day inside it. A partial or impossible date gives no error from the picker: the form validates with checks.date.
  • Choosing an available day closes the dialog at once, calls onValueChange with 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 value that 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 autocomplete value yourself (1.3.5 Identify Input Purpose (AA)). A DateInput stays in a Fieldset with a legend, help text with an example, and an error.
  • Bridge the value. value={dateInputValueToIsoDate(boxes)} (or maskedDateToIsoDate(text, locale)) in, and onValueChange={(date) => setBoxes(isoDateToDateInputValue(date))} out. Validate the field yourself (checks.date, with its range).
  • Say the range. Pass minimum and maximum and 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 marked aria-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). Never body.
  • 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} selected after the dialog has closed.
  • 3.1.2 Language of Parts (AA): the Calendar's lang when 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.

KeyWhereWhat happens
Tablast boxMoves 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+TabtriggerMoves back to the last box
Test: date-picker.test.tsx › keyboard › Shift+Tab moves from the trigger back to the last box
Tab / Shift+Tabopen dialogClose, 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
EntertriggerOpens 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
SpacetriggerOpens the dialog, as Enter
Test: date-picker.test.tsx › keyboard › Space on the trigger opens the dialog
Entertrigger, typed dateOpens on the typed date, which has aria-selected
Test: date-picker.test.tsx › keyboard › the dialog opens on the typed date when the field holds a real date
Entertrigger, a typed date outside the rangeOpens on the nearest day inside the range
Test: date-picker.test.tsx › keyboard › a typed date outside the range opens inside it
ArrowRightdayMoves 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
Enteravailable dayChooses 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
Spaceavailable dayThe same as Enter
Test: date-picker.test.tsx › keyboard › Space on an available day chooses it and closes the dialog
Enterunavailable dayNothing; the dialog stays open
Test: date-picker.test.tsx › keyboard › Enter on an unavailable day does nothing and the dialog stays open
Spaceunavailable dayNothing; the dialog stays open
Test: calendar.test.tsx › keyboard › Enter and Space on an unavailable day select nothing
Escapeopen dialogCloses 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 / SpaceCloseCloses 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).

WhenWhat it saysMessage keyPoliteness
A day is chosenThursday 15 October 2026 selectedcalendar.selectedPolite
A month button is pressedPolite

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 actionRead aloudPolitenessTest
Field and triggerthe boxes År (Year), Månad (Month), Dag (Day), then button, Välj datum (Choose date), not expandednonedate-picker.test.tsx › read aloud › reads the field, then the trigger as a button with a popup that is not expanded
Open dialogdialog, Välj ett datum (Choose a date) → heading → grid, oktober 2026 (October 2026) → the typed day, selectednonedate-picker.test.tsx › read aloud › reads the open dialog by its title, then the grid and the typed day as selected
A day chosenpolite: torsdag 15 oktober 2026 vald (Thursday 15 October 2026 selected)politedate-picker.test.tsx › read aloud › says "{date} vald" as a polite announcement when a day is chosen
Closed with Escape or Closenothingnonedate-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.

PropTypeDefaultDescription
valueIsoDate"" (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.
openboolean–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.
minimumIsoDate–The first day that can be chosen, as YYYY-MM-DD.
maximumIsoDate–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.
weekStartWeekStartThe provider’sThe first day of the week, 1 (Monday) to 7 (Sunday). Else the provider’s, the locale’s, Monday.
weekNumbersbooleanfalseISO week numbers, with a Monday start only.
todayIsoDateThe clockToday as YYYY-MM-DD, for tests and examples. Else the clock, read each time the dialog opens.
messagesPartial<KvirnMessages['datePicker']>–Replaces the trigger’s text and the dialog’s title for this picker.
calendarMessagesPartial<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 attributeValuesMeaning
kv-dialog-trigger kv-button kv-date-picker-triggeralwaysThe 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-openpresent or absentThe 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 attributeValuesMeaning
kv-dialog kv-date-picker-popupalwaysThe part classes. The default theme styles them.
aria-modal"true" while openThe page behind is inert.
aria-labelledbythe Title’s idNames the dialog. Give it a title.
data-openpresent or absentThe 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.

PropTypeDefaultDescription
as'h2' | 'h3' | 'h4' | 'h5' | 'h6''h2'The element, so the title has the level it needs in the page’s outline.
Class or attributeValuesMeaning
kv-dialog-titlealwaysThe 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

PropTypeDefaultDescription
valueIsoDate"" (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.
openboolean–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.
minimumIsoDate–The first day that can be chosen, as YYYY-MM-DD.
maximumIsoDate–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.
weekStartWeekStartThe provider’sThe first day of the week, 1 (Monday) to 7 (Sunday). Else the provider’s, the locale’s, Monday.
weekNumbersbooleanfalseISO week numbers, with a Monday start only.
todayIsoDateThe clockToday as YYYY-MM-DD, for tests and examples. Else the clock, read each time the dialog opens.
messagesPartial<KvirnMessages['datePicker']>–Replaces the trigger’s text and the dialog’s title for this picker.
calendarMessagesPartial<KvirnMessages['calendar']>–Replaces the Calendar’s strings for this picker, and "{date} selected", said on the page after the dialog has closed.

Result

PropTypeDefaultDescription
isOpenboolean–Whether the dialog is open.
triggerPropsDatePickerTriggerPartProps–Spread on the <button> that opens the picker.
popupPropsDatePickerPopupPartProps–Spread on the <dialog>. Name it with a title.
titlePropsDialogTitlePartProps–Spread on the title element. Call registerTitle from an effect in it.
closePropsDialogClosePartProps–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.
calendarPropsDatePickerCalendarOptions–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.
triggerTextstring–"Choose date": the trigger’s visible text.
titleTextstring–"Choose a date": the default title.
dialogUseDialogResult & { 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.

LanguageDefault text
SvenskaVälj datum
SuomiValitse päivämäärä
Norsk bokmålVelg dato
Norsk nynorskVel dato
EnglishChoose date

datePicker.title

The default title of the dialog.

LanguageDefault text
SvenskaVälj ett datum
SuomiValitse päivämäärä
Norsk bokmålVelg en dato
Norsk nynorskVel ein dato
EnglishChoose 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.Popup stay 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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassdate-picker.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassdate-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)passn/apass13 rows, each names a test in date-picker.test.tsx
Focus order and managementpassn/apassdate-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)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

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.