Skip to main content

Upgrading to v9

This release includes significant 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. First, read the migration guide from v7 to v8, then follow the steps below.

Checklist

1. Upgrade to the Latest Version

npm install react-day-picker@latest

If you are not using date-fns directly in your code (e.g., when using a different locale), remove it from your dependencies:

npm remove date-fns

2. Update Your Custom Styles

The default design has changed slightly. You may need to adjust DayPicker to match your design. See the styling docs for more information.

3. Add the onSelect Prop When Using selected

The selected prop is now controlled. Add an onSelect prop to handle the selected state and keep it in sync with your component.

+ const [selected, setSelected] = useState<Date | undefined>(undefined);
<DayPicker
mode="single"
selected={selected} // controlled prop
+ onSelect={setSelected} // update the selected date
/>

4. Update Class Names

Class names for UI elements have been updated for clarity and consistency. If you use custom styles via the classNames or styles prop, update them accordingly.

For example, day_disabled is now disabled:

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

Additionally, the day element is now day_button, and the cell element is now day:

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

See the full list of updated class names in the DeprecatedUI type.

List of Updated Class Names
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.

5. Replace fromDate and toDate

Replace fromDate and toDate with the hidden, startMonth, and endMonth props.

Example: Replace fromDate

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

Example: Replace toDate

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

6. Update Tests and Translations

DayPicker's ARIA labels have been updated for clarity. Update your tests and translations accordingly.

Updated ARIA Labels

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 ##

Update test selectors as needed:

- 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 year and communicates the selected and today status. See Translating DayPicker for more information.

7. Update Formatters to Return a String

Formatters now return a string instead of a ReactNode. Update your code accordingly.

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

If you need to return a ReactElement, use a custom component:

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

8. Update Custom Components

If you use the components prop, update your code as some components have changed. See the custom components guide for details.

  <DayPicker
components={{
- IconRight: MyRightIcon,
- IconLeft: MyLeftIcon,
+ Chevron: (props) => {
+ if (props.orientation === "left") {
+ return <ChevronLeftIcon {...props} />;
+ }
+ return <ChevronRightIcon {...props} />;
+ },
}}
/>
List of Updated Components
ComponentChanges
CaptionRenamed to MonthCaption.
DayNow renders a DayButton.
DayContentRemoved. Use formatDay to change content.
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.

Deprecations

Deprecated props and types will be removed in the next major version. 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 use TypeScript, some types have been deprecated for clarity and shorter names.

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

See the source of types/deprecated.ts for more details.

List of Deprecated Types
Deprecated TypeDeprecation Reason
CaptionRenamed to MonthCaption.
HeadRowRemoved.
RowRenamed to Week.
DayPickerSinglePropsRenamed to PropsSingle.
DayPickerMultiplePropsRenamed to PropsMulti.
DayPickerRangePropsRenamed to PropsRange.
DayPickerDefaultPropsRenamed to PropsBase.
DaySelectionModeRenamed to Mode.
ModifierWill be removed. Use string instead.
InternaModifierSplit into DayFlag and SelectionState.
SelectSingleEventHandlerWill be removed. Use PropsSingle["onSelect] instead.
SelectMultipleEventHandlerWill be removed. Use PropsMulti["onSelect] instead.
SelectRangeEventHandlerWill be removed. Use PropsRange["onSelect] instead.
DayPickerProviderPropsNot used anymore.
useNavigationIncluded in useDayPicker.
useDayRenderRemoved. Customize day rendering with the htmlAttributes prop in a custom Day component.
ContextProvidersPropsNot used anymore.
DayLabelUse typeof labelDay instead.
NavButtonLabelUse typeof labelNext or typeof labelPrevious instead.
WeekdayLabelUse typeof labelWeekday instead.
WeekNumberLabelUse typeof labelWeekNumber instead.
DayClickEventHandlerUse DayMouseEventHandler instead.
DayFocusEventHandlerWill be removed. Use DayEventHandler<React.FocusEvent | React.KeyboardEvent> instead.
DayKeyboardEventHandlerWill be removed. Use DayEventHandler<React.KeyboardEvent> instead.
DayMouseEventHandlerWill be removed. Use DayEventHandler<React.MouseEvent> instead.
DayPointerEventHandlerWill be removed. Use DayEventHandler<React.PointerEvent> instead.
DayTouchEventHandlerWill be removed. Use DayEventHandler<React.TouchEvent> instead.