When to use it#
- Use it for a start and an end near today, such as a stay or a leave, with a typed field for each end. You keep the form state: the picker reads both fields and gives back the finished range.
- Use it in forms for residents and for staff. Put the two fields in a group Fieldset whose legend names the range.
- Not for one date: use DatePicker.
- Not for a range far from today: let people type it.
- Not when most days are taken: offer the free periods as radio buttons.
- Not as a section of the page: use a Calendar with
mode="range".
Example#
import {
DateRangePicker,
Field,
Fieldset,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
export function StayDates() {
const { texts } = useDateRangePickerTexts()
const { locale } = useLocale()
const [fieldTexts, setFieldTexts] = useState({ start: '', end: '' })
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<div>
<DateRangePicker.Root
value={{
start: maskedDateToIsoDate(fieldTexts.start, locale),
end: maskedDateToIsoDate(fieldTexts.end, locale),
}}
onValueChange={(range) =>
setFieldTexts({
start: isoDateToMaskedDate(range.start, locale),
end: isoDateToMaskedDate(range.end, locale),
})
}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Field.Root>
<Field.Label>{texts.from}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.start}
onValueChange={(start) => setFieldTexts((current) => ({ ...current, start }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.to}</Field.Label>
<TextInput
name="end"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.end}
onValueChange={(end) => setFieldTexts((current) => ({ ...current, end }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<DateRangePicker.Trigger />
</div>
</Fieldset.Root>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}Use cases#
A stay with a longest length
Set maximumDays and write the limit in your own unit in the group’s help text. Days count both ends, so a booking of 14 nights is 15 days. The dialog writes the limit in days. Someone can still type a reversed or too long range. The example checks it when the form is sent and puts the error on the To field. It fixes today, so the dates are the same on any day.
import {
Button,
DateRangePicker,
Field,
Fieldset,
Stack,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useEffect, useRef, useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
const maximumNights = 14
const dayInMilliseconds = 24 * 60 * 60 * 1000
export function LimitedStay() {
const { texts } = useDateRangePickerTexts()
const { locale } = useLocale()
const endRef = useRef<HTMLInputElement>(null)
const [fieldTexts, setFieldTexts] = useState({ start: '', end: '' })
const [error, setError] = useState<string | undefined>(undefined)
const [isChecked, setIsChecked] = useState(false)
const [focusRequest, setFocusRequest] = useState(0)
const example = masks.date().withLocale(locale).format('2026-10-27')
useEffect(() => {
if (focusRequest > 0) {
endRef.current?.focus()
}
}, [focusRequest])
// A typed range can be reversed or too long, which the picker never produces: check it here.
const checkStay = () => {
const start = maskedDateToIsoDate(fieldTexts.start, locale)
const end = maskedDateToIsoDate(fieldTexts.end, locale)
if (start === '' || end === '') {
return texts.errorMissing(example)
}
const nights = (Date.parse(end) - Date.parse(start)) / dayInMilliseconds
if (nights < 0) {
return texts.errorOrder
}
return nights > maximumNights ? texts.errorTooLong : undefined
}
return (
<div>
<DateRangePicker.Root
today="2026-10-14"
minimum="2026-10-14"
maximumDays={maximumNights + 1}
value={{
start: maskedDateToIsoDate(fieldTexts.start, locale),
end: maskedDateToIsoDate(fieldTexts.end, locale),
}}
onValueChange={(range) => {
setFieldTexts({
start: isoDateToMaskedDate(range.start, locale),
end: isoDateToMaskedDate(range.end, locale),
})
setError(undefined)
}}
>
<Stack
className="kv-stack--gap-8"
as="form"
noValidate
onSubmit={(event) => {
event.preventDefault()
const next = checkStay()
setError(next)
setIsChecked(next === undefined)
if (next !== undefined) {
setFocusRequest((request) => request + 1)
}
}}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Field.Root>
<Field.Label>{texts.from}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.start}
onValueChange={(start) => setFieldTexts((current) => ({ ...current, start }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<Field.Root invalid={error !== undefined}>
<Field.Label>{texts.to}</Field.Label>
<TextInput
ref={endRef}
name="end"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.end}
onValueChange={(end) => setFieldTexts((current) => ({ ...current, end }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
<Field.ErrorMessage>{error}</Field.ErrorMessage>
</Field.Root>
<DateRangePicker.Trigger />
</div>
<Fieldset.HelpText>{texts.limit}</Fieldset.HelpText>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.check}
</Button>
<output>{isChecked ? texts.checked : null}</output>
</Stack>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}Props in this example:
maximumDayson DateRangePicker.Rootminimumon DateRangePicker.Roottodayon DateRangePicker.Root
Warning: Don't forget
The picker never checks what is typed, so a reversed or too long range reaches your form (3.3.1 Error Identification). Check it, and say what is wrong and how to fix it. See What you need to do.
Days that are taken
A day that can’t be chosen stays reachable with the keyboard and shows as unavailable (struck through in the default theme). The reason is part of its name, so a screen reader reads it. By default a range cannot pass over such a day. Set allowUnavailableInRange when it can, such as a leave across a holiday.
import {
DateRangePicker,
Field,
Fieldset,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
const bookedDays = new Set(['2026-10-20', '2026-10-21'])
export function BookedDays() {
const { texts } = useDateRangePickerTexts()
const { locale } = useLocale()
const [fieldTexts, setFieldTexts] = useState({ start: '', end: '' })
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<div>
<DateRangePicker.Root
today="2026-10-14"
isDateUnavailable={(date) => bookedDays.has(date)}
getDateDescription={(date) => (bookedDays.has(date) ? texts.closed : undefined)}
value={{
start: maskedDateToIsoDate(fieldTexts.start, locale),
end: maskedDateToIsoDate(fieldTexts.end, locale),
}}
onValueChange={(range) =>
setFieldTexts({
start: isoDateToMaskedDate(range.start, locale),
end: isoDateToMaskedDate(range.end, locale),
})
}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Field.Root>
<Field.Label>{texts.from}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.start}
onValueChange={(start) => setFieldTexts((current) => ({ ...current, start }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.to}</Field.Label>
<TextInput
name="end"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.end}
onValueChange={(end) => setFieldTexts((current) => ({ ...current, end }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<DateRangePicker.Trigger />
</div>
</Fieldset.Root>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}Props in this example:
isDateUnavailableon DateRangePicker.RootgetDateDescriptionon DateRangePicker.Root
A dialog title that asks your question
The default title says “Choose the dates”. A title that repeats the group’s question tells the user which dates they are choosing.
import {
DateRangePicker,
Field,
Fieldset,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
export function TitledStay() {
const { texts } = useDateRangePickerTexts()
const { locale } = useLocale()
const [fieldTexts, setFieldTexts] = useState({ start: '', end: '' })
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<div>
<DateRangePicker.Root
messages={{ title: texts.title }}
value={{
start: maskedDateToIsoDate(fieldTexts.start, locale),
end: maskedDateToIsoDate(fieldTexts.end, locale),
}}
onValueChange={(range) =>
setFieldTexts({
start: isoDateToMaskedDate(range.start, locale),
end: isoDateToMaskedDate(range.end, locale),
})
}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Field.Root>
<Field.Label>{texts.from}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.start}
onValueChange={(start) => setFieldTexts((current) => ({ ...current, start }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.to}</Field.Label>
<TextInput
name="end"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.end}
onValueChange={(end) => setFieldTexts((current) => ({ ...current, end }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<DateRangePicker.Trigger />
</div>
</Fieldset.Root>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}Props in this example:
messageson DateRangePicker.Root
Information: Did you know?
To change the text for your whole app, pass messages to KvirnProvider instead.
Dates in separate boxes for day, month and year
A resident reports the days they were away, which they know from memory. Give each end a DateInput instead of a masked field, and put the group of each end in its own Fieldset with a legend. Put the one trigger after the end’s boxes. The picker works the same with either.
import {
DateInput,
DateRangePicker,
Fieldset,
dateInputValueToIsoDate,
isoDateToDateInputValue,
useDateInput,
} from '@kvirn-ui/react'
import type { DateInputValue } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
const boxes = { day: DateInput.Day, month: DateInput.Month, year: DateInput.Year }
const emptyDate: DateInputValue = { year: '', month: '', day: '' }
export function AbsenceDates() {
const { texts } = useDateRangePickerTexts()
const { order } = useDateInput()
const [start, setStart] = useState<DateInputValue>(emptyDate)
const [end, setEnd] = useState<DateInputValue>(emptyDate)
const hint = order[0] === 'year' ? texts.hintYearFirst : texts.hintDayFirst
return (
<div>
<DateRangePicker.Root
value={{ start: dateInputValueToIsoDate(start), end: dateInputValueToIsoDate(end) }}
onValueChange={(range) => {
setStart(isoDateToDateInputValue(range.start))
setEnd(isoDateToDateInputValue(range.end))
}}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.absenceLegend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Fieldset.Root group>
<Fieldset.Legend>{texts.firstDay}</Fieldset.Legend>
<DateInput.Root name="start" value={start} onValueChange={setStart}>
{order.map((part) => {
const Box = boxes[part]
return <Box key={part} />
})}
</DateInput.Root>
<Fieldset.HelpText>{hint}</Fieldset.HelpText>
</Fieldset.Root>
<Fieldset.Root group>
<Fieldset.Legend>{texts.lastDay}</Fieldset.Legend>
<DateInput.Root name="end" value={end} onValueChange={setEnd}>
{order.map((part) => {
const Box = boxes[part]
return <Box key={part} />
})}
<DateRangePicker.Trigger />
</DateInput.Root>
<Fieldset.HelpText>{hint}</Fieldset.HelpText>
</Fieldset.Root>
</div>
</Fieldset.Root>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}A booking of at least two days, in a season
Set minimumDays for the fewest days, counting both ends, and maximum for the last day that can be chosen. A day that would make the range too short says so in its name (“fewer than 2 days”). Write both limits in the group’s help text.
For example 27/10/2026
For example 27/10/2026
Hire it for at least 2 days, between 14 October and 31 December 2026.
import {
DateRangePicker,
Field,
Fieldset,
TextInput,
isoDateToMaskedDate,
masks,
maskedDateToIsoDate,
useLocale,
} from '@kvirn-ui/react'
import { useState } from 'react'
import { useDateRangePickerTexts } from './texts.ts'
export function HallBooking() {
const { texts } = useDateRangePickerTexts()
const { locale } = useLocale()
const [fieldTexts, setFieldTexts] = useState({ start: '', end: '' })
const example = masks.date().withLocale(locale).format('2026-10-27')
return (
<div>
<DateRangePicker.Root
today="2026-10-14"
minimum="2026-10-14"
maximum="2026-12-31"
minimumDays={2}
value={{
start: maskedDateToIsoDate(fieldTexts.start, locale),
end: maskedDateToIsoDate(fieldTexts.end, locale),
}}
onValueChange={(range) =>
setFieldTexts({
start: isoDateToMaskedDate(range.start, locale),
end: isoDateToMaskedDate(range.end, locale),
})
}
>
<Fieldset.Root group>
<Fieldset.Legend>{texts.hallLegend}</Fieldset.Legend>
<div className="kv-date-range-row">
<Field.Root>
<Field.Label>{texts.hallFrom}</Field.Label>
<TextInput
name="start"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.start}
onValueChange={(start) => setFieldTexts((current) => ({ ...current, start }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.hallTo}</Field.Label>
<TextInput
name="end"
mask={masks.date()}
className="kv-input--width-10"
value={fieldTexts.end}
onValueChange={(end) => setFieldTexts((current) => ({ ...current, end }))}
/>
<Field.HelpText>{texts.hint(example)}</Field.HelpText>
</Field.Root>
<DateRangePicker.Trigger />
</div>
<Fieldset.HelpText>{texts.hallLimit}</Fieldset.HelpText>
</Fieldset.Root>
<DateRangePicker.Popup />
</DateRangePicker.Root>
</div>
)
}Props in this example:
minimumDayson DateRangePicker.Rootmaximumon DateRangePicker.Rootminimumon DateRangePicker.Root
Warning: Don't forget
A typed range can still break a limit, and the picker doesn’t check it. Check it when the form is sent, as in the stay with a longest length (3.3.1 Error Identification).
Accessibility#
What it does for you#
- APG pattern: Date Picker Dialog (a modal dialog around a grid), after two typed fields. APG has no range pattern: a range is two ordinary selections. The grid is described on the Calendar page (range mode), the dialog on the Dialog page, and the single-date sibling on the DatePicker page.
- Deviations: none new, and no key is added. From the APG example: no OK and Cancel buttons (the second press closes; Close and Escape cancel); the month is announced by Announcer on a button press; 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">(two of them on a wide screen).
DateRangePicker is an add-on to two typed fields (a From and a To, each one masks.date() TextInput, or each a DateInput): typing always works, and the dialog is the slower path for keyboard and screen reader users. It is controlled only: it keeps no range of its own. The fields' range goes in as value ({ start, end }, each as year-month-day such as 2026-10-15, or '' for an empty end) and the chosen range comes out once, through onValueChange, for the consumer to write into both fields. The one masked field per end is the default composition; the three-box DateInput per end is supported with every feature. There is no defaultOpen: a picker never starts open.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Root | none (renders no element) | none | Owns the open state, the draft range and the Dialog's context |
| Trigger | <button type="button"> → button | name = its visible text dateRangePicker.trigger; aria-haspopup="dialog"; aria-expanded true/false | One, after both fields. The calendar icon is decorative (aria-hidden). Classes kv-button kv-date-range-picker-trigger; data-open while open |
| Popup | native <dialog> → dialog | aria-modal="true" while open; aria-labelledby → Title | Class kv-dialog kv-date-range-picker-popup. Top layer; the page behind is inert |
| Title | <h2> (tabindex="-1") | none | dateRangePicker.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, range mode: aria-multiselectable, aria-selected on the range | Mounted only while the dialog is open. Two grids on a wide screen, one on a narrow one. The step line (choose the start, choose the end) is in the range hint |
Rules the automated tests check:
- Opens on the typed start, else the typed end, else today, kept inside
minimum–maximum. The step follows: a start only gives the end step; an end only gives the start step; both give a finished range (a press starts a new one); an end before the start shows as the start alone and is never rewritten. A partial or impossible text counts as no date and gives no error from the picker: the form validates. - Press 1 sets the draft start (fields unchanged, dialog open, "Start date … Choose the end date." announced in the dialog). Press 2 on a possible end closes at once, calls
onValueChangeonce with the finished range, and the consumer writes both fields. A day that can't be the end (before the start, too short, too long, past an unavailable day) becomes the new start and says so (restart, not swap). An unavailable day does nothing. - Escape and Close drop the draft: both fields stay as they were,
onValueChangeis not called, and the next opening starts from the typed range. - Dev warnings (once): an end that is not in the form year-month-day; a part used outside a DateRangePicker.Root.
What you need to do#
- Keep the typed fields. DateRangePicker never replaces them: typing always works, and each keeps
autocompletewhere it applies (1.3.5 Identify Input Purpose (AA)) and avoids dragging (2.5.7 Dragging Movements (AA)). Put both in a groupFieldsetwith a legend ("Dates of your stay"), give each its own label and example, and put the error on the To field (Field.ErrorMessage, or the Fieldset's). - Bridge both ends.
value={{ start: maskedDateToIsoDate(from, locale), end: maskedDateToIsoDate(to, locale) }}(ordateInputValueToIsoDateper DateInput) in, andonValueChange={(range) => …}out, oneisoDateToMaskedDateorisoDateToDateInputValueper end. Validate the order and the span yourself (the picker never produces a reversed or over-long range, but a typed one can be). - Say the limits. Pass
minimum,maximum,minimumDaysandmaximumDaysand put them in the help text too (3.3.2 Labels or Instructions (A)); a booking says nights (14 nights ismaximumDays={15}). - Name the task. Replace the title with the question ("Choose the dates of your stay").
- Put the one trigger after both fields. The Popup can sit in a page
<form>: none of its buttons submits it. - Not for a range far from today (type it), nor when many days are unavailable (use radio buttons).
- Everything in the Calendar and Dialog contracts applies.
Warning: Don't forget
Write the limits in the group’s help text too. The dialog shows them only once it is open (3.3.2 Labels or Instructions).
Visual and modes#
- Focus indicator: the trigger and Close are Buttons and have the Button's focus ring; the grids' is in the Calendar contract.
- Target size: the trigger is a Button, and the day cells are larger than the 24 by 24 CSS pixel minimum of 2.5.8 Target Size (Minimum) (AA), also on a narrow screen.
- Layout: the fields and the trigger sit in
kv-date-range-row, which wraps: side by side on a wide screen, stacked on a narrow one, the trigger last (at 320px or 200% text it wraps below the To field). On a wide screen the popup is as wide as its calendar, with two months; on a narrow screen it shows one month, and below that it is a sheet. - Forced colours: in forced colours (the user's own system colours) it behaves as the Dialog and the Calendar do, and the trigger is a Button.
- Reduced motion: the picker adds no motion of its own; the Dialog's opening motion is the only motion.
Focus management#
- Without a provider
timeZone, "today" is the UTC date on first paint only. The Calendars mount 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 start, else the typed end, 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 (the Dialog's approved deviation), so there is no keyboard trap (2.1.2 No Keyboard Trap (A)). - Restore to: the trigger, for the end, Escape and Close alike. If the trigger is gone, the first input in the trigger's nearest
fieldset, group or field: with two masked fields in one row that is the From field; with a Fieldset per end it is the end's first box (the closer landing spot). 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 grids (checked by tests and axe).
- 3.3.2 Labels or Instructions (A): the range hint and the fields' help text. 3.3.7 Redundant Entry (A): the typed range is the starting point. 2.5.7 Dragging Movements (AA): no dragging is needed.
- 4.1.3 Status Messages (AA): the step and the finished range, the latter after the dialog has closed.
- 3.1.2 Language of Parts (AA): the Calendar's
langwhen the browser has no data for the locale. - 2.5.3 Label in Name (A): the trigger is named by its visible text.
- 2.4.7 Focus Visible (AA), 2.4.11 Focus Not Obscured (Minimum) (AA): the trigger and Close are Buttons with the Button's ring, the grids' ring is the Calendar's, and nothing inside is sticky. The ring is checked by eye.
- 1.4.3 Contrast (Minimum) (AA), 1.4.11 Non-text Contrast (AA): the dialog and the grids use the Dialog's and the Calendar's colours, measured by the theme's contrast check, and axe finds no violation in any story, closed or open.
- 1.4.10 Reflow (AA): the reflow sweep checks every story at 320 CSS pixels for horizontal overflow.
- 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 size of the sheet and the day cells is checked by eye.
Keyboard#
- Focus
- native for the fields, the trigger and the dialog's buttons; roving tabindex in the grids (Calendar), one Tab stop across both months
- Selection follows focus
- no (Enter or Space selects)
- Arrows wrap
- no (they cross months and the two grids, as in Calendar)
- Shortcuts
- none
The grids' own keys (arrows, Home, End, Page keys, month buttons, the two-month crossings and the press outcomes) are on the Calendar page 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 | From field | Moves to the To field Test: date-range-picker.test.tsx › keyboard › Tab moves from the From field to the To field and on to the trigger |
| Tab | To field | Moves to the one trigger, after both fields Test: date-range-picker.test.tsx › keyboard › Tab moves from the From field to the To field and on to the trigger |
| Shift+Tab | trigger | Moves back to the To field, then the From field Test: date-range-picker.test.tsx › keyboard › Shift+Tab moves from the trigger back to the To field and the From field |
| Tab / Shift+Tab | open dialog | Close, the month buttons, then both grids 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-range-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 start, else the end, else today (both fields empty) Test: date-range-picker.test.tsx › keyboard › Enter on the trigger opens the dialog with focus on today when both fields are empty |
| Space | trigger | Opens the dialog, as Enter Test: date-range-picker.test.tsx › keyboard › Space on the trigger opens the dialog |
| Enter | trigger, a typed range | Opens on the typed start, the typed range selected Test: date-range-picker.test.tsx › keyboard › the dialog opens on the typed start, with the whole typed range selected |
| Enter | trigger, a start only | Opens on the start at the end step Test: date-range-picker.test.tsx › keyboard › with only a start typed the dialog opens on it at the end step |
| Enter | trigger, an end only | Opens on the end at the start step Test: date-range-picker.test.tsx › keyboard › with only an end typed the dialog opens on it at the start step |
| Enter | trigger, an end before the start | Opens on the start at the end step; nothing is rewritten Test: date-range-picker.test.tsx › keyboard › an end typed before the start opens on the start at the end step, nothing rewritten |
| Enter | trigger, partial text | Counts as no date: opens on today Test: date-range-picker.test.tsx › keyboard › partial text counts as no date: the dialog opens on today |
| Control, Alt or Meta + Enter | trigger | Not taken Test: date-range-picker.test.tsx › keyboard › a key with Control, Alt or Meta on the trigger does not open the dialog |
| ArrowRight | day | Moves to the next day inside the dialog (the rest as Calendar) Test: date-range-picker.test.tsx › keyboard › an arrow key moves between days inside the dialog |
| Enter | available day, start step | Sets the start; the dialog stays open; the step line says to choose the end Test: date-range-picker.test.tsx › keyboard › Enter on a day sets the start: the dialog stays open, the fields are unchanged and the step line says to choose the end |
| Enter | possible end | Chooses it: closes, fills both fields, focus to the trigger Test: date-range-picker.test.tsx › keyboard › Enter on the end closes the dialog, fills both fields and returns focus to the trigger |
| Space | possible end | The same as Enter Test: date-range-picker.test.tsx › keyboard › Space on the end chooses it and closes the dialog |
| Enter | start again, end step | A one-day range; closes Test: date-range-picker.test.tsx › keyboard › Enter on the start again makes a one-day range and closes |
| Enter | day before the start | Becomes the new start, announced; the dialog stays open Test: date-range-picker.test.tsx › keyboard › a day before the start restarts: it becomes the new start and the dialog stays open |
| Enter | day that makes the range too long | Becomes the new start, announced; its name says why Test: date-range-picker.test.tsx › keyboard › a day that makes the range too long restarts, says so in its name, and the dialog stays open |
| Enter / Space | unavailable day | Nothing; the dialog stays open Test: date-range-picker.test.tsx › keyboard › Enter on an unavailable day does nothing and the dialog stays open |
| Escape | open dialog, a start pressed | Closes; the half-chosen range is dropped; both fields unchanged; focus to the trigger Test: date-range-picker.test.tsx › keyboard › Escape after the first press discards the half-chosen range: both fields stay as they were and focus returns to the trigger |
| Escape | reopened | Opens on the typed range again, not on the dropped start Test: date-range-picker.test.tsx › keyboard › the dialog reopens on the typed range, not on the half-chosen one dropped by Escape |
| Enter / Space | Close | Closes; the draft is dropped; focus to the trigger Test: date-range-picker.test.tsx › keyboard › the Close button discards the half-chosen range and returns focus to the trigger |
A click on a day presses it the same way. With the trigger gone, focus goes to the first box of the group around it.
Announcements#
DateRangePicker 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 |
|---|---|---|---|
| The start is pressed | calendar.rangeChooseEnd | Polite | |
| A day restarts the range | calendar.rangeChooseEnd | Polite | |
| The end is chosen | calendar.rangeSelected | Polite | |
| A month button is pressed | calendar.visibleMonths | Polite |
The text in all five languages
Change the text#
For your whole app, pass messages to KvirnProvider. For one DateRangePicker, pass its messages prop.
<KvirnProvider messages={{ calendar: { rangeChooseEnd: '…' } }}>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 |
|---|---|---|---|
| The fields and the trigger | From, To, then button, Välj datumen (Choose the dates), not expanded | none | date-range-picker.test.tsx › read aloud › reads the From field, the To field, then the trigger as a button with a popup that is not expanded |
| Open dialog, typed range | dialog, Välj perioden (Choose the period) → heading → grid, oktober 2026 (October 2026) → grid, november 2026 (November 2026) → the start day, read with startdatum (start date) and selected, and the end day, read with slutdatum (end date) and selected | none | date-range-picker.test.tsx › read aloud › reads the open dialog by its title, then both grids and the typed range as selected |
| The start is pressed | polite: Startdatum fredag 16 oktober 2026. Välj slutdatum. (Start date Friday 16 October 2026. Choose the end date.) | polite | date-range-picker.test.tsx › read aloud › says "Startdatum … Välj slutdatum." as a polite announcement when the start is pressed |
| The end is chosen | after close: polite: fredag 16 oktober 2026 till fredag 23 oktober 2026 valda, 8 dagar (Friday 16 October 2026 to Friday 23 October 2026 selected, 8 days) | polite | date-range-picker.test.tsx › read aloud › says "{start} till {end} valda, {length}" as a polite announcement when the end is chosen |
| Closed with Escape or Close | nothing | none | date-range-picker.test.tsx › announcements › closing with Escape announces nothing and … › closing with Close announces nothing |
API reference#
import { DateRangePicker, useDateRangePicker } from '@kvirn-ui/react'DateRangePicker.Root
Renders No element. It owns the open state, the draft range (the days pressed so far) and the limits, and gives the Dialog its context. Inside it, put the group Fieldset with the From and To fields and one DateRangePicker.Trigger after both, then DateRangePicker.Popup. Put the fields and the trigger in a div with the class kv-date-range-row: it wraps on a narrow screen. Each end can be a masked TextInput or a DateInput. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
value | DateRange | { start: "", end: "" } | The range the two fields hold, { start, end } as YYYY-MM-DD, "" for a date that is empty or partial. Build each end with dateInputValueToIsoDate or maskedDateToIsoDate. DateRangePicker is controlled only: it never writes the fields itself. |
onValueChange | (range: DateRange) => void | – | Called once, with the finished range, when the end is chosen. Write both ends into your fields, then. Escape and Close never call it. |
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: DateRangePickerChangeDetails) => 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 the end 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. |
minimumDays | number | – | The fewest days, counting both ends (a one-day range is 1). |
maximumDays | number | – | The most days, counting both ends. A booking of 14 nights is 15. |
allowUnavailableInRange | boolean | false | Lets a range pass over an unavailable day. By default it blocks. |
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['dateRangePicker']> | – | 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 "{start} to {end} selected", said on the page after the dialog has closed. |
DateRangePicker.Trigger
Renders A <button type="button"> named “Choose dates” (dateRangePicker.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-range-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. |
DateRangePicker.Popup
Renders A modal <dialog>, a Dialog popup. With no children it holds the Title, a Close button and the range 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-range-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. |
DateRangePicker.Title
Renders An <h2> that names the dialog, “Choose the dates” (dateRangePicker.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. |
DateRangePicker.Calendar
Renders A Calendar.Root in range mode with the picker’s draft and limits set, and the month buttons, both headings, the range hint and both grids inside it (the second month shows on screens 64rem wide or more). It takes the attributes of a <div>, not the Calendar’s options: those come from the picker. Give it children to compose your own.
useDateRangePicker
Takes the same options as DateRangePicker.Root. Render the Calendar only while isOpen: it reads the range when it mounts.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
value | DateRange | { start: "", end: "" } | The range the two fields hold, { start, end } as YYYY-MM-DD, "" for a date that is empty or partial. Build each end with dateInputValueToIsoDate or maskedDateToIsoDate. DateRangePicker is controlled only: it never writes the fields itself. |
onValueChange | (range: DateRange) => void | – | Called once, with the finished range, when the end is chosen. Write both ends into your fields, then. Escape and Close never call it. |
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: DateRangePickerChangeDetails) => 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 the end 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. |
minimumDays | number | – | The fewest days, counting both ends (a one-day range is 1). |
maximumDays | number | – | The most days, counting both ends. A booking of 14 nights is 15. |
allowUnavailableInRange | boolean | false | Lets a range pass over an unavailable day. By default it blocks. |
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['dateRangePicker']> | – | 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 "{start} to {end} selected", said on the page after the dialog has closed. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Whether the dialog is open. |
triggerProps | DateRangePickerTriggerPartProps | – | Spread on the <button> that opens the picker. |
popupProps | DateRangePickerPopupPartProps | – | 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 | DateRangePickerCalendarOptions | – | The Calendar’s options (mode "range", the draft value, the limits, two visible months): spread them on Calendar.Root while the dialog is open. Its own "selected" messages are off, because the page says the range after the dialog has closed. |
triggerText | string | – | "Choose dates": the trigger’s visible text. |
titleText | string | – | "Choose the dates": the default title. |
dialog | UseDialogResult & { isShown: boolean } | – | The Dialog behind the picker, for DateRangePicker.Root. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one DateRangePicker, pass its messages prop.
dateRangePicker.trigger
The visible text and name of the trigger.
| Language | Default text |
|---|---|
| Svenska | Välj datumen |
| Suomi | Valitse päivät |
| Norsk bokmål | Velg datoer |
| Norsk nynorsk | Vel datoar |
| English | Choose dates |
dateRangePicker.title
The default title of the dialog.
| Language | Default text |
|---|---|
| Svenska | Välj perioden |
| Suomi | Valitse päivämäärät |
| Norsk bokmål | Velg datoene |
| Norsk nynorsk | Vel datoane |
| English | Choose the dates |
Known issues#
- Screen reader users: a screen reader may not say the finished range when focus lands on the trigger. Check with your users.
- Screen reader users:
aria-selectedon every day between the ends may be noisy. Test it with your own screen reader users. - Children you pass to
DateRangePicker.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-range-picker.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | date-range-picker.test.tsx (axe and role, name and state): there is one trigger after both fields: 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 | 23 rows, each names a test in date-range-picker.test.tsx |
| Focus order and management | pass | n/a | pass | date-range-picker.test.tsx: Enter on the trigger opens the dialog with focus on today when both fields are 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 through From, To and "Choose dates". Press Enter: the dialog is read by its title, and focus is on the typed start (or today).
- Press Enter on a day: the dialog stays open and "Start date …. Choose the end date." is read.
- Press Enter on a later day: the dialog closes, both fields fill, focus is on the button, and the range and its length are read.
- Press Enter on a day before the start: it becomes the new start and this is announced.
- Start a range, then press Escape: both fields are unchanged and focus is on the button.
- With a longest stay set, a day too far away says so in its name.