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';Props
DatePicker 17 props
Earliest date allowed; earlier days are disabled.
Latest date allowed; later days are disabled.
Show the header (title, headline and mode toggle).
Show the calendar ↔ text input toggle.
Start in calendar or text input mode.
First and last years of the year list (and of a range's month list). Years outside
min/maxare shown disabled.Web density of the input mode's text fields,
0to-3: each step takes 4px off them (56px at 0, 44px at -3). The calendar keeps its size: M3 doesn't make date pickers denser, since their 48px day targets are part of their accessibility. Left out, the fields take the density of the nearestThemeProviderorThemeScope.The root
<div>'s id.Ref to the root
<div>element.The selected date (controlled);
nullfor none.Initial date when uncontrolled.
Text
Words the picker shows and announces, with English defaults. A
LabelsProvidersets them for the whole app.The header's title in calendar mode.
The title in text input mode (the M3 modal date input's "Enter date").
Headline when nothing is selected.
The previous month button.
The next month button.
Tooltip of the previous-month button, naming its shortcut.
Tooltip of the next-month button, naming its shortcut.
The month and year button while the days show.
The month and year button while the years show.
Tooltip of the month and year button, naming its shortcut.
Name of the year list.
The mode toggle in calendar mode.
The mode toggle in text input mode.
Label of the input mode's field.
Label of a range's start field in input mode.
Label of a range's end field in input mode, and the headline's end while a range is being picked ("Mar 20 – End date").
The format hint shown below the field and as its placeholder.
Error when the text isn't a date.
Error for a date before
minor aftermax.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The picker's root;
classNameis merged here too.The header: title, headline and mode toggle.
The header's title ("Select date").
The header's headline: the chosen date or range.
The calendar or the text input below the header.
The weekday names above the days.
Each day of the calendar.
Each year of the year list.
The month and year button above the days, which shows the year list.
Each month's subhead in the range picker's scrolling month list.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DateRangePicker 18 props
Earliest date allowed; earlier days are disabled.
Latest date allowed; later days are disabled.
Show the header (title, headline and mode toggle).
Show the calendar ↔ text input toggle.
Start in calendar or text input mode.
First and last years of the year list (and of a range's month list). Years outside
min/maxare shown disabled.Web density of the input mode's text fields,
0to-3: each step takes 4px off them (56px at 0, 44px at -3). The calendar keeps its size: M3 doesn't make date pickers denser, since their 48px day targets are part of their accessibility. Left out, the fields take the density of the nearestThemeProviderorThemeScope.The root
<div>'s id.Ref to the root
<div>element.The selected range (controlled);
nullfor none.Initial range when uncontrolled.
scrolllists the months one under another and scrolls vertically, as the M3 modal range picker does;pagedshows one month at a time with previous / next buttons and a year list, like the date picker.
Events
Called with the range once both its start and end are picked or typed.
Text
Words the picker shows and announces, with English defaults. A
LabelsProvidersets them for the whole app.The header's title in calendar mode.
The title in text input mode (the M3 modal date input's "Enter date").
Headline when nothing is selected.
The previous month button.
The next month button.
Tooltip of the previous-month button, naming its shortcut.
Tooltip of the next-month button, naming its shortcut.
The month and year button while the days show.
The month and year button while the years show.
Tooltip of the month and year button, naming its shortcut.
Name of the year list.
The mode toggle in calendar mode.
The mode toggle in text input mode.
Label of the input mode's field.
Label of a range's start field in input mode.
Label of a range's end field in input mode, and the headline's end while a range is being picked ("Mar 20 – End date").
The format hint shown below the field and as its placeholder.
Error when the text isn't a date.
Error for a date before
minor aftermax.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The band behind a range's days: each calendar cell it spans (
data-rangeisstart,middleorend), whose background paints it.The picker's root;
classNameis merged here too.The header: title, headline and mode toggle.
The header's title ("Select date").
The header's headline: the chosen date or range.
The calendar or the text input below the header.
The weekday names above the days.
Each day of the calendar.
Each year of the year list.
The month and year button above the days, which shows the year list.
Each month's subhead in the range picker's scrolling month list.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DateField 32 props
The field's label, e.g. "Date of birth".
The date (controlled);
nullfor none.Initial date when uncontrolled.
Earliest date allowed; earlier days are disabled.
Latest date allowed; later days are disabled.
First and last years of the year menu; years outside min / max are disabled.
Whether the dropdown calendar is open (controlled).
Whether the dropdown calendar starts open when uncontrolled.
Helper text below the field.
Marks the field invalid, with
errorMessagebelow it.Error text shown below the field while it's invalid, in place of
supportingText.The field must have a date.
The field and its calendar button can't be used.
The date can be read and focused but not changed.
Read as
invalidwhen that's left out, for a form library that sets the attribute.Read as
requiredwhen that's left out, for a form library that sets the attribute.Read as
readOnlywhen that's left out, for a form library that sets the attribute.Form field name; the input submits the typed text.
The
<input>'s id, for a<label for>or an error summary's link.Icon of the button that opens the calendar.
Web density of the typed field,
0to-3: each step takes 4px off it (56px at 0, 44px at -3). The calendar keeps its size: M3 doesn't make date pickers denser, since their 48px day targets are part of their accessibility. Left out, the field takes the density of the nearestThemeProviderorThemeScope.The text field's root.
The
<input>.
Events
A date was typed and committed, or picked and confirmed;
nullwhen cleared.Called when the dropdown calendar opens or closes.
Text
More description for the
<input>, after the supporting or error text: the ids of elements such as a hint that the date must come after another field's.The id of an element with more details about the
<input>.Words the field and its calendar show and announce, with English defaults. A
LabelsProvidersets them for the whole app.The calendar icon button.
Name of the dropdown calendar.
The previous month button.
The next month button.
Tooltip of the previous month button.
Tooltip of the next month button.
The previous year button.
The next year button.
Tooltip of the previous year button.
Tooltip of the next year button.
Added to the month menu button's name.
Added to the year menu button's name.
Tooltip of the month menu button.
Tooltip of the year menu button.
Name of the month list.
Name of the year list.
The calendar's dismissing action.
The calendar's confirming action.
The format hint shown below the field and as its placeholder.
Error when the text isn't a date.
Error for a date before
minor aftermax.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The text field's root;
classNamegoes here too.The
<input>.The calendar's panel: the dropdown panel, or on compact windows the full-screen dialog's surface.
The calendar's weekday names.
Each day of the calendar.
Each month or year in the calendar's month and year lists.
The floating label.
The filled or outlined container around the label, input and icons.
The built-in error icon.
The outlined field's border (a
<fieldset>, notched for the floated label).The trailing icon's 48px box.
The helper text below the field.
The error message below the field.
The filled field's active indicator, the line along the container's bottom.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-date-picker-modal-header-headline-color | var(--md-sys-color-on-surface-variant) | The headline: the picked date or range. | DatePickerModalTokens.HeaderHeadlineColor |
--md-comp-date-picker-modal-date-selected-container-color | var(--md-sys-color-primary) | The circle of a picked day (and of both ends of a range). | DatePickerModalTokens.DateSelectedContainerColor |
--md-comp-date-picker-modal-date-selected-label-text-color | var(--md-sys-color-on-primary) | The number of a picked day. | DatePickerModalTokens.DateSelectedLabelTextColor |
--md-comp-date-picker-modal-date-today-container-outline-color | var(--md-sys-color-primary) | The 1px outline of today's date. | DatePickerModalTokens.DateTodayContainerOutlineColor |
--md-comp-date-picker-modal-date-today-label-text-color | var(--md-sys-color-primary) | The number of today's date. | DatePickerModalTokens.DateTodayLabelTextColor |
--md-comp-date-picker-modal-range-selection-active-indicator-container-color | var(--md-sys-color-secondary-container) | The band behind the days of a range. | DatePickerModalTokens.RangeSelectionActiveIndicatorContainerColor |
--md-comp-date-picker-modal-container-color | var(--md-sys-color-surface-container-high) | The dialog panel. | DatePickerModalTokens.ContainerColor |
--md-comp-date-picker-modal-container-shape | var(--md-sys-shape-corner-extra-large) | The dialog panel's corners. | DatePickerModalTokens.ContainerShape |
--md-comp-date-picker-modal-container-elevation | var(--md-sys-elevation-level-3) | The dialog panel's shadow. | DatePickerModalTokens.ContainerElevation |
Spec status
Built to the M3 Expressive date picker spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Docked date picker | Built | Variant · Field |
| Modal date picker | Built | Variant · Modal, Basic |
| Modal date input | Built | Variant · Input |
| Docked: day, month and year selection | Built | Configuration · Field |
| Modal: single date selection | Built | Configuration · Modal, Basic |
| Modal: date range selection | Built | Configuration · Range modal, Range |
| Modal: year selection | Built | Configuration · Basic, Modal |
| Modal input: single date input | Built | Configuration · Input |
| Modal input: date range input | Built | Configuration · Input |
| Full screen on compact windows | Built | Use case · Range modal, Modal |
| Density of the typed fields | Extension | density (0 to -3, or the theme's) takes 4px a step off the docked field and the input mode's fields, as text fields; the calendar keeps its 48px days, since M3 doesn't make date pickers denser. |
monthLayout="paged" | Extension | The range picker scrolls a vertical list of months as the spec says; paged shows one month at a time instead. |
| Docked date range | Not built | The spec’s docked picker is single-date; a range uses the modal range picker. |
Docked date picker
BuiltVariant · Field
Modal date input
BuiltVariant · Input
Docked: day, month and year selection
BuiltConfiguration · Field
Modal: date range selection
BuiltConfiguration · Range modal, Range
Modal input: single date input
BuiltConfiguration · Input
Modal input: date range input
BuiltConfiguration · Input
Full screen on compact windows
BuiltUse case · Range modal, Modal
Density of the typed fields
Extensiondensity(0 to -3, or the theme's) takes 4px a step off the docked field and the input mode's fields, as text fields; the calendar keeps its 48px days, since M3 doesn't make date pickers denser.
ExtensionmonthLayout="paged"The range picker scrolls a vertical list of months as the spec says;
pagedshows one month at a time instead.Docked date range
Not builtThe spec’s docked picker is single-date; a range uses the modal range picker.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
DatePicker,DateRangePicker: 49.7 kBDateField: 62.1 kB
Differences from Compose
- 360px wide with Compose's header, 56px month row, weekday row and six 48px week rows (the height is kept at six). Days are 40px circles: selected
primary/on-primary, today a 1pxprimaryoutline, disabled at 38%. - The modal picker pages months with the arrows, a horizontal swipe or the keyboard, and each month slides in from its side (a fade with reduced motion). The range picker scrolls a vertical list of months, each under a
title-smallsubhead;monthLayout="paged"pages it instead. - In a range, the ends are filled and the days between sit on a 40px
secondary-containerband drawn as cell background gradients, so nothing is positioned (it mirrors in RTL). - The docked calendar is a
surface-container-highpanel with 16px corners at level 3, with a month menu and a year menu, each between its own previous / next buttons, the days of the months around inon-surface-variant, and Cancel / OK. On compact windows (below 600px) the calendar button opens the modal picker full screen instead, as M3 recommends: the 360px panel doesn't fit a phone. - Dates are written the locale's way (the order of the parts, the month and day names, the first day of the week): the nearest
LocaleProvider's, or the browser's language without one, which may not be the page's.