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';

Props

By name or description, across the 67 props below

DatePicker 17 props

  • mintype DateValue

    Earliest date allowed; earlier days are disabled.

  • maxtype DateValue

    Latest date allowed; later days are disabled.

  • isDateUnavailabletype ((date: DateValue) => boolean)

    Returns true for a day that can't be picked (it shows disabled).

  • headertype booleandefault true

    Show the header (title, headline and mode toggle).

  • modeToggletype booleandefault true

    Show the calendar ↔ text input toggle.

  • defaultModetype "calendar" | "input"default "calendar"

    Start in calendar or text input mode.

  • yearRangetype [number, number]default [1900, 2100]

    First and last years of the year list (and of a range's month list). Years outside min / max are shown disabled.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density of the input mode's text fields, 0 to -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 nearest ThemeProvider or ThemeScope.

  • idtype string

    The root <div>'s id.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

  • valuetype CalendarDate | null

    The selected date (controlled); null for none.

  • defaultValuetype CalendarDate | nulldefault null

    Initial date when uncontrolled.

Events

  • onChangetype ((value: CalendarDate) => void)

    Called with the date the user picks or types.

Text

  • labelstype Partial<DatePickerLabels>

    Words the picker shows and announces, with English defaults. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DateRangePicker 18 props

  • mintype DateValue

    Earliest date allowed; earlier days are disabled.

  • maxtype DateValue

    Latest date allowed; later days are disabled.

  • isDateUnavailabletype ((date: DateValue) => boolean)

    Returns true for a day that can't be picked (it shows disabled).

  • headertype booleandefault true

    Show the header (title, headline and mode toggle).

  • modeToggletype booleandefault true

    Show the calendar ↔ text input toggle.

  • defaultModetype "calendar" | "input"default "calendar"

    Start in calendar or text input mode.

  • yearRangetype [number, number]default [1900, 2100]

    First and last years of the year list (and of a range's month list). Years outside min / max are shown disabled.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density of the input mode's text fields, 0 to -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 nearest ThemeProvider or ThemeScope.

  • idtype string

    The root <div>'s id.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

  • valuetype DateRange | null

    The selected range (controlled); null for none.

  • defaultValuetype DateRange | nulldefault null

    Initial range when uncontrolled.

  • monthLayouttype "scroll" | "paged"default "scroll"

    scroll lists the months one under another and scrolls vertically, as the M3 modal range picker does; paged shows one month at a time with previous / next buttons and a year list, like the date picker.

Events

  • onChangetype ((value: DateRange) => void)

    Called with the range once both its start and end are picked or typed.

Text

  • labelstype Partial<DatePickerLabels>

    Words the picker shows and announces, with English defaults. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DateField 32 props

  • labeltype ReactNodeRequired

    The field's label, e.g. "Date of birth".

  • valuetype CalendarDate | null

    The date (controlled); null for none.

  • defaultValuetype CalendarDate | nulldefault null

    Initial date when uncontrolled.

  • mintype DateValue

    Earliest date allowed; earlier days are disabled.

  • maxtype DateValue

    Latest date allowed; later days are disabled.

  • isDateUnavailabletype ((date: DateValue) => boolean)

    Returns true for a day that can't be picked (it shows disabled).

  • yearRangetype [number, number]default [1900, 2100]

    First and last years of the year menu; years outside min / max are disabled.

  • opentype boolean

    Whether the dropdown calendar is open (controlled).

  • defaultOpentype booleandefault false

    Whether the dropdown calendar starts open when uncontrolled.

  • supportingTexttype ReactNodedefault the locale's format, such as "MM/DD/YYYY" in en-US

    Helper text below the field.

  • invalidtype boolean

    Marks the field invalid, with errorMessage below it.

  • errorMessagetype ReactNode

    Error text shown below the field while it's invalid, in place of supportingText.

  • requiredtype booleandefault false

    The field must have a date.

  • disabledtype booleandefault false

    The field and its calendar button can't be used.

  • readOnlytype booleandefault false

    The date can be read and focused but not changed.

  • aria-invalidtype boolean | "false" | "true" | "grammar" | "spelling"

    Read as invalid when that's left out, for a form library that sets the attribute.

  • aria-requiredtype Booleanish

    Read as required when that's left out, for a form library that sets the attribute.

  • aria-readonlytype Booleanish

    Read as readOnly when that's left out, for a form library that sets the attribute.

  • nametype string

    Form field name; the input submits the typed text.

  • idtype string

    The <input>'s id, for a <label for> or an error summary's link.

  • calendarIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon of the button that opens the calendar.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density of the typed field, 0 to -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 nearest ThemeProvider or ThemeScope.

  • reftype Ref<HTMLDivElement>

    The text field's root.

  • inputReftype Ref<HTMLInputElement>

    The <input>.

Events

  • onChangetype ((value: CalendarDate | null) => void)

    A date was typed and committed, or picked and confirmed; null when cleared.

  • onOpenChangetype ((open: boolean) => void)

    Called when the dropdown calendar opens or closes.

Text

  • aria-describedbytype string

    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.

  • aria-detailstype string

    The id of an element with more details about the <input>.

  • labelstype Partial<DateFieldLabels>

    Words the field and its calendar show and announce, with English defaults. A LabelsProvider sets them for the whole app.

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.

Date picker tokens (md-comp-date-picker-modal)
VariableDefaultPaintsCompose
--md-comp-date-picker-modal-header-headline-colorvar(--md-sys-color-on-surface-variant)The headline: the picked date or range.DatePickerModalTokens.HeaderHeadlineColor
--md-comp-date-picker-modal-date-selected-container-colorvar(--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-colorvar(--md-sys-color-on-primary)The number of a picked day.DatePickerModalTokens.DateSelectedLabelTextColor
--md-comp-date-picker-modal-date-today-container-outline-colorvar(--md-sys-color-primary)The 1px outline of today's date.DatePickerModalTokens.DateTodayContainerOutlineColor
--md-comp-date-picker-modal-date-today-label-text-colorvar(--md-sys-color-primary)The number of today's date.DatePickerModalTokens.DateTodayLabelTextColor
--md-comp-date-picker-modal-range-selection-active-indicator-container-colorvar(--md-sys-color-secondary-container)The band behind the days of a range.DatePickerModalTokens.RangeSelectionActiveIndicatorContainerColor
--md-comp-date-picker-modal-container-colorvar(--md-sys-color-surface-container-high)The dialog panel.DatePickerModalTokens.ContainerColor
--md-comp-date-picker-modal-container-shapevar(--md-sys-shape-corner-extra-large)The dialog panel's corners.DatePickerModalTokens.ContainerShape
--md-comp-date-picker-modal-container-elevationvar(--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.

  • 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.

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 kB
  • DateField: 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 1px primary outline, 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-small subhead; monthLayout="paged" pages it instead.
  • In a range, the ends are filled and the days between sit on a 40px secondary-container band drawn as cell background gradients, so nothing is positioned (it mirrors in RTL).
  • The docked calendar is a surface-container-high panel 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 in on-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.