Forms
DatePicker
Free27.1 KB gzippedA date field: type a date in the locale's short format (or ISO), or press the calendar button to pick one from a Calendar in a popup dialog.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Alt+Arrow Down, Arrow Left, Arrow Right and 9 more · Full report
Import
import { DatePicker, Calendar, DateRangePicker } from "@vjdesigns/vjdesigns-ui";
Importing only DatePicker adds about 27.1 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Type a date or pick one from the calendar. Values are ISO strings like "2026-10-14".
Value: null
import { useState } from "react";
import { DatePicker, Field, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [date, setDate] = useState<string | null>(null);
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="Start date">
<DatePicker value={date} onValueChange={setDate} clearable />
</Field>
<Text size="sm" tone="muted">
Value: <code>{String(date)}</code>
</Text>
</Stack>
);
}
Limits
min, max and isDateDisabled limit which dates can be chosen. Here, weekends are off.
Weekdays only, within the next 30 days.
import { DatePicker, Field } from "@vjdesigns/vjdesigns-ui";
export function Limits() {
return (
<div style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="Delivery day" hint="Weekdays only, within the next 30 days.">
<DatePicker
min={new Date().toISOString().slice(0, 10)}
max={new Date(Date.now() + 30 * 864e5).toISOString().slice(0, 10)}
isDateDisabled={(_, date) => date.getDay() === 0 || date.getDay() === 6}
/>
</Field>
</div>
);
}
Range
DateRangePicker picks a start and end date, showing two months by default.
import { DateRangePicker, Field } from "@vjdesigns/vjdesigns-ui";
export function Range() {
return (
<div style={{ width: "100%", maxWidth: "24rem" }}>
<Field label="Trip dates">
<DateRangePicker />
</Field>
</div>
);
}
Inline calendar
Calendar is the grid on its own, for always-visible date selection.
October 2026
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
import { Calendar } from "@vjdesigns/vjdesigns-ui";
export function InlineCalendar() {
return <Calendar aria-label="Pick a date" defaultValue="2026-10-14" />;
}
Accessibility
The calendar follows the WAI-ARIA date picker pattern: arrow keys move by day and week, Page Up / Page Down by month (with Shift, by year), Home / End to the week's edges, and Enter selects. People can also just type the date; the expected format is described to screen readers.
You can type the date or pick it from the calendar.
import { DatePicker, Field } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<div style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="Check-in date" hint="You can type the date or pick it from the calendar.">
<DatePicker min="2026-10-20" defaultValue="2026-10-24" clearable />
</Field>
</div>
);
}
Regional formats
Formats follow the region, not just the language. The same value shows as 10/24/2026 in en-US, 24/10/2026 in en-GB and 24.10.2026 in de-DE, and the calendar starts on Sunday or Monday to match. Set locale per field, or once for the whole app with LocaleProvider. Override the first day with weekStartsOn. The value is always the ISO date "2026-10-24", whatever the region or time zone.
import { DatePicker, Field, Stack } from "@vjdesigns/vjdesigns-ui";
export function RegionalFormats() {
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="United States (en-US)">
<DatePicker locale="en-US" defaultValue="2026-10-24" />
</Field>
<Field label="United Kingdom (en-GB)">
<DatePicker locale="en-GB" defaultValue="2026-10-24" />
</Field>
<Field label="Germany (de-DE)">
<DatePicker locale="de-DE" defaultValue="2026-10-24" />
</Field>
<Field label="United States, weeks start Monday">
<DatePicker locale="en-US" weekStartsOn={1} defaultValue="2026-10-24" />
</Field>
</Stack>
);
}
Translated
The typed format, month and weekday names, the first day of the week and the buttons' names all come from the locale. In Japanese the field shows 2026/10/24 and the calendar starts on Sunday.
2026年10月
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
|---|---|---|---|---|---|---|
import {
Calendar,
DatePicker,
Field,
Stack,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import ja from "@vjdesigns/vjdesigns-ui/locales/ja";
export function Translated() {
return (
<LocaleProvider locale="ja" messages={ja}>
<Stack gap={4} style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="予約日">
<DatePicker defaultValue="2026-10-24" />
</Field>
<Calendar aria-label="日付を選択" defaultValue="2026-10-24" />
</Stack>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
Value: null
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
The value is an ISO date string ("YYYY-MM-DD"), so it never shifts with time zones. The text field shows it in the locale's numeric format; on blur (or Enter), typed text is parsed and normalized, or rejected with an inline error. Inside a Field, label, hint, error, required, disabled, and invalid state are wired to the text input.
The popup is a modal Popover on the shared overlay layer stack, so Escape closes only the calendar, also inside a Modal or Drawer.
<Field label="Game day">
<DatePicker name="gameDay" min="2026-10-01" onValueChange={setDay} />
</Field>
API reference
DatePicker
| Prop | Type | Default |
|---|---|---|
valueSelected date, "YYYY-MM-DD", or null for none (controlled). | ISODate | null | — |
defaultValueInitially selected date when uncontrolled. | ISODate | null | — |
onValueChangeCalled with the new ISO date (or null) when the user picks a date, types one and leaves the field, or clears it. Typed text that isn't a valid, allowed date sets the value to null. | (value: ISODate | null) => void | — |
minEarliest allowed date, "YYYY-MM-DD". | ISODate | — |
maxLatest allowed date, "YYYY-MM-DD". | ISODate | — |
isDateDisabledMarks individual dates unavailable. Receives the ISO date and a local | (date: ISODate, dateObject: Date) => boolean | — |
localeBCP 47 locale for the typed format, the calendar, and labels. Defaults to the browser locale. | string | — |
weekStartsOnFirst day of the week in the calendar. Defaults to the locale's. | 0123456 | — |
placementWhere the calendar popup opens relative to the field. Flips when there isn't room. | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom-start" |
sizeField and calendar size. Inherits from a surrounding | "sm""md""lg" | "md" |
nameName of a hidden input that submits the ISO value ("YYYY-MM-DD") with a form. | string | — |
clearableShows a clear button while there is text. | boolean | false |
openControlled open state of the calendar popup. | boolean | — |
defaultOpenInitial open state of the calendar popup when uncontrolled. | boolean | false |
onOpenChangeCalled when the calendar popup opens or closes. | (open: boolean) => void | — |
onInvalidInputCalled when the user leaves the field with text that isn't a valid, allowed date. Use it to set your own | (error: DateInputError) => void | — |
invalidMessageMessage shown under the field when typed text is rejected. Pass a function to word it per reason, or | ReactNode | ((error: DateInputError) => ReactNode) | — |
chooseDateLabelAccessible name of the calendar button while no date is set. | string | "Choose date" |
changeDateLabelAccessible name of the calendar button while a date is set. | (formattedDate: string) => string | (date) => `Change date, ${date}` |
dialogLabelAccessible name of the calendar popup dialog. | string | "Choose date" |
formatDescriptionScreen-reader description of the expected format. | (pattern: string) => string | (pattern) => `Format: ${pattern}` |
todayOverride "today" ("YYYY-MM-DD") in the calendar, e.g. for tests. | ISODate | — |
numberOfMonthsMonths shown in the popup. | 12 | 1 |
fieldClassNameClass name for the Input's field wrapper. | string | — |
refRef to the | Ref<HTMLInputElement> | — |
startIconDecorative icon before the text. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the text. Hidden from assistive technology. | ReactNode | — |
loadingShows a decorative spinner at the end and sets | boolean | false |
fullWidthStretches the field to fill its container. | boolean | true |
variantVisual style. | "outline""filled" | "outline" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
invalidMarks the value as invalid: sets | boolean | false |
clearLabelAccessible name of the clear button. | string | "Clear" |
inputClassNameClass name for the | string | — |
startAddonStatic content attached to the start edge, such as | ReactNode | — |
endAddonStatic content attached to the end edge, such as | ReactNode | — |
startElementInteractive content inside the start edge (for example an | ReactNode | — |
endElementInteractive content inside the end edge (for example a copy or show-password | ReactNode | — |
htmlSizeThe native | number | — |
Also accepts standard HTML attributes, plus className, style and ref.
Calendar
A month grid for picking a date or a date range, following the WAI-ARIA date picker grid pattern: arrow keys move by day and week, Home/End to the week's edges, PageUp/PageDown by month (with Shift, by year), and Enter or Space selects. One date is in the tab order (roving tabindex).
Dates are plain ISO strings ("YYYY-MM-DD"), so values never shift with time zones. Use parseISODate / toISODate to convert to and from Date.
<Calendar defaultValue="2026-10-04" onValueChange={setDate} />
<Calendar mode="range" numberOfMonths={2} onValueChange={setRange} />
| Prop | Type | Default |
|---|---|---|
modeSelect one date. | "single""range" | "single" |
valueSelected date, "YYYY-MM-DD", or null for none (controlled). | ISODate | null | DateRange | null | — |
defaultValueInitially selected date when uncontrolled. | ISODate | null | DateRange | null | — |
onValueChangeCalled with the selected ISO date. | (value: ISODate | null) => void | (value: DateRange) => void | — |
minEarliest selectable date, "YYYY-MM-DD". Keyboard navigation stops here. | ISODate | — |
maxLatest selectable date, "YYYY-MM-DD". Keyboard navigation stops here. | ISODate | — |
isDateDisabledMarks individual dates unavailable ( | (date: ISODate, dateObject: Date) => boolean | — |
localeBCP 47 locale for month names, weekday names, and date labels. Defaults to the browser locale. | string | — |
weekStartsOnFirst day of the week (0 = Sunday ... 6 = Saturday). Defaults to the locale's first day where the browser exposes it ( | 0123456 | — |
monthVisible month, "YYYY-MM" (controlled). With two months, this is the first one. | ISOMonth | — |
defaultMonthInitially visible month, "YYYY-MM". Defaults to the selected date's month, or today's. | ISOMonth | — |
onMonthChangeCalled with the new visible month ("YYYY-MM") when the user pages or moves focus to another month. | (month: ISOMonth) => void | — |
numberOfMonthsMonths shown side by side. | 12 | 1 |
showOutsideDaysShow the leading and trailing days of neighbouring months (muted). They can be pressed to select them and jump to that month. Defaults to | boolean | — |
sizeDay cell and text size. | "sm""md""lg" | "md" |
todayOverride "today" ("YYYY-MM-DD"), e.g. for tests or a server-provided date. Defaults to the local date. | ISODate | — |
headingLevelHeading level of the month title. Pick it by document outline. | 23456 | 2 |
previousMonthLabelAccessible name of the previous-month button. | string | "Previous month" |
nextMonthLabelAccessible name of the next-month button. | string | "Next month" |
Also accepts standard HTML attributes, plus className, style and ref.
DateRangePicker
A date range field: two text fields (start and end) typed in the locale's short format, plus a calendar button that opens a range Calendar (two months by default) in a modal popup.
The value is { start, end } with ISO dates ("YYYY-MM-DD"). In the calendar, the first pick sets the start and the second the end; the range is committed (and the popup closes) only when both are picked, so Escape after one pick changes nothing. Typed dates are validated like DatePicker's, plus an end before the start is rejected.
Accessibility: the pair is a role="group" named by the Field label (or aria-label); each field is named by that label plus its own visible label ("Season dates, Start date"). Field hint, error, required, disabled, and invalid state reach both fields. Errors are announced politely.
<Field label="Season dates">
<DateRangePicker startName="from" endName="to" onValueChange={setRange} />
</Field>
| Prop | Type | Default |
|---|---|---|
valueSelected range (controlled). | DateRange | null | — |
defaultValueInitially selected range when uncontrolled. | DateRange | null | — |
onValueChangeCalled with the new range when the user completes a pick in the calendar, or types a date in either field and leaves it. Typed text that isn't a valid, allowed date clears that end. | (value: DateRange) => void | — |
minEarliest allowed date, "YYYY-MM-DD". | ISODate | — |
maxLatest allowed date, "YYYY-MM-DD". | ISODate | — |
isDateDisabledMarks individual dates unavailable. Receives the ISO date and a local | (date: ISODate, dateObject: Date) => boolean | — |
localeBCP 47 locale for the typed format, the calendar, and labels. Defaults to the browser locale. | string | — |
weekStartsOnFirst day of the week in the calendar. Defaults to the locale's. | 0123456 | — |
placementWhere the calendar popup opens. Flips when there isn't room. | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom-start" |
sizeField and calendar size. Inherits from a surrounding | "sm""md""lg" | "md" |
startNameName of a hidden input that submits the start date ("YYYY-MM-DD") with a form. | string | — |
endNameName of a hidden input that submits the end date ("YYYY-MM-DD") with a form. | string | — |
openControlled open state of the calendar popup. | boolean | — |
defaultOpenInitial open state of the calendar popup when uncontrolled. | boolean | false |
onOpenChangeCalled when the calendar popup opens or closes. | (open: boolean) => void | — |
onInvalidInputCalled when the user leaves a field with text that isn't a valid, allowed date. | (error: DateRangeInputError) => void | — |
invalidMessageMessage shown under the fields when typed text is rejected. Pass a function to word it per reason, or | ReactNode | ((error: DateRangeInputError) => ReactNode) | — |
startLabelVisible label of the start field (read after the Field label). | string | "Start date" |
endLabelVisible label of the end field (read after the Field label). | string | "End date" |
chooseRangeLabelAccessible name of the calendar button while no range is set. | string | "Choose dates" |
changeRangeLabelAccessible name of the calendar button while a range is set. | (formattedRange: string) => string | (range) => `Change dates, ${range}` |
dialogLabelAccessible name of the calendar popup dialog. | string | "Choose dates" |
formatDescriptionScreen-reader description of the expected format. | (pattern: string) => string | (pattern) => `Format: ${pattern}` |
todayOverride "today" ("YYYY-MM-DD") in the calendar, e.g. for tests. | ISODate | — |
numberOfMonthsMonths shown in the popup. | 12 | 2 |
invalidMarks the fields invalid. Inherits from a surrounding | boolean | — |
requiredBoth dates are required. Inherits from a surrounding | boolean | — |
disabledDisables both fields and the calendar button. Inherits from a surrounding | boolean | — |
readOnlyRead-only fields, no calendar button. Inherits from a surrounding | boolean | — |
fullWidthStretch to the container's width. | boolean | true |
aria-labelAccessible name of the pair when there is no surrounding | string | — |
aria-describedbyExtra description ids for both fields. | string | — |
classNameClass name for the outer root. | string | — |
styleStyle for the outer root. | CSSProperties | — |
idid of the start field (the Field label points here). | string | — |
See what changed in each version in the Changelog.
Accessibility report
DatePicker targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Typing | Enter a date in the field; Enter applies it. |
| Alt+Arrow Down | Opens the calendar. |
| Arrow LeftArrow Right | Previous or next day (mirrored right to left). |
| Arrow UpArrow Down | Same day of the previous or next week. |
| HomeEnd | First or last day of the week. |
| Page UpPage Down | Previous or next month (Shift: year). |
| EnterSpace | Selects the focused day. |
| Escape | Closes the calendar and returns focus to the field. |
The calendar is a modal popover: focus moves into the grid on open and returns on close.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Text field | textbox | aria-describedby → format hint and error |
| Calendar button | button | aria-haspopup="dialog", aria-expanded, aria-label |
| Month | grid | aria-labelledby → month heading |
| Day | gridcell | aria-selected, aria-current="date" on today, aria-disabled |
| Month heading | heading | aria-live="polite" |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |