Skip to main content

Upgrading to v9

This release includes important updates related to accessibility, styles, internationalization and performance. See the changelog for the full list of changes.

Upgrading from v7

If you are upgrading from v7, this guide is still valid for you. Read first the migration guide from v7 to v8 and then follow the steps below.

Checklist

1. Upgrade to the latest version

npm install react-day-picker@latest

Remove date-fns from your dependencies if you are not using it directly in your code, like when using a different locale.

npm remove date-fns

2. Update your custom styles

The default design is slightly changed, so you may need to adjust DayPicker again to match your design. See the styling docs for more information.

3. Update the class names

This version updates the name of the UI elements to be more clear and consistent, so the class names have changed.

If you are using custom styles via classNames or styles prop, you will need to update some of them.

For example, day_disabled is now disabled:

 <DayPicker
classNames={{
- day_disabled: 'day-disabled',
+ disabled: 'day-disabled', // applies `.day_disabled` to disabled days
}}
/>

Please note that the day element is now day_button, and that the cell element is now day:

 <DayPicker
classNames={{
- cell: 'day-cell',
+ day: 'day-cell',
- day: 'day-button',
+ day_button: 'day-button',
}}
/>

See the following list of updated class names. The DeprecatedUI type lists all the deprecated class names.

List of updated ClassNames
Old NameNew Name
buttonbutton_previous, button_next
button_resetbutton_previous, button_next
captionmonth_caption
caption_betweenRemoved
caption_dropdownsdropdowns
caption_endRemoved
caption_startRemoved
cellday – ⚠️ The previous day element is now day_button.
day_disableddisabled
day_hiddenhidden
day_outsideoutside
day_range_endrange_end
day_range_middlerange_middle
day_range_startrange_start
day_selectedselected
day_todaytoday
dropdown_iconchevron
dropdown_monthmonths_dropdown
dropdown_yearyears_dropdown
headRemoved
head_cellweekday
head_rowweekdays
multiple_monthsRemoved. Use data-multiple-months data attribute.
nav_buttonbutton_previous, button_next
nav_button_nextbutton_next
nav_button_previousbutton_previous
nav_iconchevron, button_next, button_previous
rowweek
tablemonth_grid
tbodyweeks
tfootfooter
vhiddenRemoved
weeknumberweek_number
with_weeknumberRemoved. Use data-week-numbers data attribute.

4. Remove use of fromDate, toDate

In case you are using fromDate or toDate, replace them with the hidden and startMonth, endMonth prop.

Removed propNotes
fromDateReplace it with startMonth and the hidden prop and the before Matcher.
toDateReplace it with endMonth the hidden prop and the after Matcher.

Example

To replace fromDate:

 <DayPicker
- fromDate={new Date(2010, 11, 03)}
+ startMonth={new Date(2010, 11)}
+ hidden={[{ before: new Date(2010, 11, 03) }]}
/>

To replace toDate:

 <DayPicker
- toDate={new Date(2010, 11, 03)}
+ endMonth={new Date(2010, 11)}
+ hidden={[{ after: new Date(2010, 11, 03) }]}
/>

5. Update tests and translations

DayPicker relies on ARIA labels to make the calendar accessible, and v9 include some updates to make them more clear and descriptive. Following the upgrade, you may need to update your tests and translations.

Updated ARIA labels

The following ARIA labels have been updated:

LabelOld labelNew label
labelDayButton
ex labelDay
21st November (Monday)Monday, November 21st, 2024
Monday, November 21st, 2024, selected
Today, November 21st, 2024
labelPreviousGo to previous monthGo to the Previous Month
labelNextGo to next monthGo to the Next Month
labelWeekNumberWeek nr. ##Week ##

You may need to update your test selectors — for example:

./test.js
- screen.getByRole('button', 'Go to next month');
+ screen.getByRole('button', 'Go to the Next Month');

labelDay changes

The labelDay function has been renamed to labelDayButton. It now includes the the year and communicates the selected and today status. See Translating DayPicker for more information.

6. Update formatters to return a string

The formatters now are functions returning a string instead of a ReactNode. In case you are using the formatters, update your code to return a string.

  <DayPicker
formatters={{
- formatCaption: (month) => <strong>{format(month, "LLLL y")}</strong> // ❌ returned an element
+ formatCaption: (month) => format(month, "LLLL y") // ✅ return a string
}}
/>;

If your formatters are returning a ReactNode, you can use a custom component to return a ReactElement:

<DayPicker
formatters={{
formatCaption: (month) => format(month, "LLLL y") // ✅ return a string
}}
components={{
Caption: ({ children }) => <strong>{children}</strong> // ✅ return a ReactElement
}}
/>

7. Update your Custom Components

In case you are using the components prop, you may need to update your code, as some components have been updated.

  <DayPicker
components={{
- IconLeft: MyLeftIcon,
+ Chevron: (props) {
+ if (props.orientation === "left") {
+ return <MyLeftIcon {...props} />;
+ }
+ return <Chevron {...props} />;
+ }
}}
/>
List of Updated Components
ComponentsChanges
CaptionRenamed to MonthCaption.
DayNow it renders a DayButton.
DayContentRemoved. Change its content with formatDay.
HeadRemoved.
HeadRowRenamed to Weekdays.
IconDropdownRemoved. The icon is rendered by Chevron.
IconLeftRemoved. The icon is rendered by Chevron.
IconRightRemoved. The icon is rendered by Chevron.
RowRenamed to Week.

DayPicker hooks

In v8, you could use the DayPicker Hooks to access the DayPicker state and methods. In v9, these have been merged in the updated useDayPicker hook.

Deprecations

Deprecated props and types will be removed in the next major version, and it is recommended to update your code to avoid breaking changes.

Deprecated props

Deprecated propReplacementNotes
fromMonthstartMonthRenamed. The start month for the navigation.
toMonthendMonthRenamed. The end month for the navigation.
fromYearstartMonthPass the first month of the year to startMonth
toYearendMonthPass the last month of the year to endMonth.

Example

  <DayPicker
- fromYear={2010}
+ startMonth={new Date(2010, 0)} // January 2010
- toYear={2021}
+ endMonth={new Date(2021, 11)} // December 2021
/>

Deprecated types

If you are using TypeScript, some typings have been deprecated in favor of clarity and shorter names.

- import type { DayPickerDefaultProps } from 'react-day-picker';
+ import type { PropsBase } from 'react-day-picker';

See also the source of types/deprecated.ts.

List of Deprecated Types
Deprecated TypeDeprecation Reason
CaptionThis component has been renamed. Use MonthCaption instead.
HeadRowThis component has been removed.
RowThis component has been renamed. Use Week instead.
DayPickerSinglePropsThis type has been renamed. Use PropsSingle instead.
DayPickerMultiplePropsThis type has been renamed. Use PropsMulti instead.
DayPickerRangePropsThis type has been renamed. Use PropsRange instead.
DayPickerDefaultPropsThis type has been renamed. Use PropsBase instead.
DaySelectionModeThis type has been renamed. Use Mode instead.
ModifierThis type will be removed. Use string instead.
SelectSingleEventHandlerThis type will be removed. Use PropsSingle["onSelect] instead.
SelectMultipleEventHandlerThis type will be removed. Use PropsMulti["onSelect] instead.
SelectRangeEventHandlerThis type will be removed. Use PropsRange["onSelect] instead.
DayPickerProviderPropsThis type is not used anymore.
useNavigationThis type has been included in useDayPicker.
useDayRenderThis hook has been removed. To customize the rendering of a day, use the htmlAttributes prop in a custom Day component.
ContextProvidersPropsThis type is not used anymore.
DayLabelUse typeof labelDay instead.
NavButtonLabelUse typeof labelNext or typeof labelPrevious instead.
WeekdayLabelUse typeof labelWeekday instead.
WeekNumberLabelUse typeof labelWeekNumber instead.
DayClickEventHandlerUse DayMouseEventHandler instead.
DayFocusEventHandlerThis type will be removed. Use DayEventHandler<React.FocusEvent | React.KeyboardEvent> instead.
DayKeyboardEventHandlerThis type will be removed. Use DayEventHandler<React.KeyboardEvent> instead.
DayMouseEventHandlerThis type will be removed. Use DayEventHandler<React.MouseEvent> instead.
DayPointerEventHandlerThis type will be removed. Use DayEventHandler<React.PointerEvent> instead.
DayTouchEventHandlerThis type will be removed. Use DayEventHandler<React.TouchEvent> instead.