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
| Key | Action | Where |
|---|---|---|
| Arrow Left or Arrow Right | Moves to the previous or next day.In the calendar grid | In the calendar grid |
| Arrow Up or Arrow Down | Moves to the same day of the previous or next week.In the calendar grid | In the calendar grid |
| Page Up or Page Down | Moves to the same date in the previous or next month.In the calendar grid | In the calendar grid |
| Shift + Page Up or Shift + Page Down | Moves to the same date in the previous or next year.In the calendar grid | In the calendar grid |
| Home or End | Moves to the first or last day of the month.In the calendar grid | In the calendar grid |
| Space | Selects the focused day. In a range picker the first day picks the start and the second the end.In the calendar grid | In the calendar grid |
| Enter | Selects 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 | In the calendar grid |
| Shift + M | Moves 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 | In the calendar |
| Shift + Y | Opens the year list with focus on the current year.In the calendar | In the calendar |
| Escape | In a range picker, first drops a half-picked range. Otherwise it closes the docked calendar or the dialog without saving.In the calendar | In the calendar |
| Arrow Up or Arrow Down or Arrow Left or Arrow Right | Moves 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 | In the year and month lists |
| Enter or Space | Chooses 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 | In the year and month lists |
| Enter | Reads 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 | 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 AriauseCalendarGrid) of day buttons undercolumnheaderweekdays. The year and month lists areradiogroups ofradios. The docked calendar is adialog, 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 namedlabels.yearList("Year") andlabels.monthList("Month"), the docked calendarlabels.calendar("Choose a date"), and the field by itslabel. - States announced
- Selected and unavailable days. Years and months are checked or not (
aria-checked); those outsidemin/maxare disabled (aria-disabled) but stay focusable. The calendar button hasaria-haspopup="dialog"andaria-expanded, and the month and year buttons havearia-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'saria-describedbyandaria-detailsdescribe its input after the helper or error text, for a hint such as "After the start date". Anaria-invalid,aria-requiredoraria-readonlya form library sets is read asinvalid,requiredorreadOnlywhen 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
secondaryoutline 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
PickerDialogkeeps 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
supportingTextwith text that still gives the format. Put your own rule's message inerrorMessagewithinvalid. - Translate every built-in word through
labels, including the shortcut tooltips, so the keys they name stay right.