Skip to content

Date picker

Pick a single date or a range on a month grid or by typing, docked below a field or in a dialog.

import { DatePicker, DateRangePicker, DateField } from '@windmorph/react';

Keyboard

Date picker keyboard
KeyAction
Arrow Left or Arrow RightMoves to the previous or next day.In the calendar grid
Arrow Up or Arrow DownMoves to the same day of the previous or next week.In the calendar grid
Page Up or Page DownMoves to the same date in the previous or next month.In the calendar grid
Shift + Page Up or Shift + Page DownMoves to the same date in the previous or next year.In the calendar grid
Home or EndMoves to the first or last day of the month.In the calendar grid
SpaceSelects the focused day. In a range picker the first day picks the start and the second the end.In the calendar grid
EnterSelects the focused day, then closes the calendar and saves it: in the docked calendar always, and in a PickerDialog given onConfirm. A range saves once both ends are picked; otherwise Enter only selects.In the calendar grid
Shift + MMoves to the month menu: the docked calendar opens its month list on the current month; the modal picker focuses its month and year button.In the calendar
Shift + YOpens the year list with focus on the current year.In the calendar
EscapeIn a range picker, first drops a half-picked range. Otherwise it closes the docked calendar or the dialog without saving.In the calendar
Arrow Up or Arrow Down or Arrow Left or Arrow RightMoves between years (three to a row in the modal picker's list) or, in the docked calendar's lists, up and down between months or years. Options outside min / max are skipped.In the year and month lists
Enter or SpaceChooses the year or month and goes back to the days: the modal picker returns focus to the same day of the chosen year, the docked one to the menu button.In the year and month lists
EnterReads and reformats the typed date. In a PickerDialog given onConfirm it also closes the dialog and saves a usable date (for a range, from the end date field).In a typed date
  • Left and right are mirrored in right-to-left layouts, in the grid and in the year list.
  • The previous and next buttons' tooltips name their shortcuts ("Previous month (Page Up)", "Next year (Shift+Page Down)"), and so do the month and year buttons' ("Choose a year (Shift+Y)"). A tooltip describes its button (aria-describedby).
  • The scrolling range picker (monthLayout="scroll") has no month or year menu, so Shift+M and Shift+Y do nothing there.
  • The typed date has no input mask: it accepts dashes, spaces, slashes or dots and an optional leading zero, and is reformatted only on Enter or when you leave the field.

Screen reader

Role
The month is a grid (React Aria useCalendarGrid) of day buttons under columnheader weekdays. The year and month lists are radiogroups of radios. The docked calendar is a dialog, opened from an icon button at the end of a text field.
Accessible name
Each day is named by its full date, and each weekday header by its full name (abbr, also shown on hover). The grid is named by the month it shows. The lists are named labels.yearList ("Year") and labels.monthList ("Month"), the docked calendar labels.calendar ("Choose a date"), and the field by its label.
States announced
Selected and unavailable days. Years and months are checked or not (aria-checked); those outside min / max are disabled (aria-disabled) but stay focusable. The calendar button has aria-haspopup="dialog" and aria-expanded, and the month and year buttons have aria-expanded. A typed date that can't be used makes the field invalid, with the reason as its error text.
  • The headline and the month label are aria-live="polite", so a new selection and a new month are announced.
  • The locale's format ("MM/DD/YYYY") is the field's placeholder and helper text. The locale is the nearest LocaleProvider's, or the browser's language without one.
  • DateField's aria-describedby and aria-details describe its input after the helper or error text, for a hint such as "After the start date". An aria-invalid, aria-required or aria-readonly a form library sets is read as invalid, required or readOnly when those are left out.
  • The drop-down arrows are decorative (aria-hidden), and so are the empty cells around each month in the scrolling range picker.

Focus

  • The docked calendar opens with focus on the selected day (or today), keeps focus inside while open, and returns it to the calendar button when it closes.
  • In a PickerDialog, focus is contained in the dialog and returned to what opened it on close.
  • The grid is one Tab stop: focus moves between days with the keys above. Each year or month list is one Tab stop, on the checked option, with a roving tabIndex.
  • Days, years and months show M3's focus indicator on keyboard focus only: a 3px secondary outline 2px outside.

Touch target

  • Days are 40px circles with a 48 × 48px target filling their cell. Years are 72 × 36px pills whose target is 48px tall. The docked calendar's months and years are 48px rows.
  • The previous, next, mode and calendar buttons are icon buttons with 48 × 48px targets.
  • A horizontal swipe on the grid pages months; the previous and next buttons and Page Up / Page Down do the same without a gesture.

Motion

  • Under reduced motion a new month fades in without sliding, the calendar and text input modes swap with a fade only (the height of the picker changes at once instead of on a spring), and the year list fades in without expanding.
  • A PickerDialog keeps only its fades under reduced motion.

What you need to do

  • Give the field (label) or the dialog (aria-label) a name that says what the date is for ("Date of birth", "Check-in").
  • Keep the format as helper text, or replace supportingText with text that still gives the format. Put your own rule's message in errorMessage with invalid.
  • Translate every built-in word through labels, including the shortcut tooltips, so the keys they name stay right.