Current month should update when passed values change
See original GitHub issueMoving this conversation over from https://github.com/airbnb/react-dates/issues/17.
Because SingleDatePicker
and DateRangePicker
month props are controlled internally, there’s no way of programmatically changing the month once the component has already been mounted and used. https://github.com/airbnb/react-dates/issues/17 solves the initialVisibleMonth
but there are still use cases not covered.
Examples:
- A form has multiple datepickers. Even after initially opening, if one of the datepickers is selected, all the other form inputs should set their
currentMonth
to match - Allowing a HoC to control
currentMonth
will make it easier to arbitrarily jumpn
months back (see https://github.com/airbnb/react-dates/issues/29)
One proposal I have is to overhaul the API so that animation effects are triggered by watching for the currentMonth prop to change. We’d let a HoC always control the displayed month and pressing the “next month” button would just trigger a callback that the HoC would have to use to update currentMonth. Maybe if currentMonth
is passed as a prop, use that instead of https://github.com/airbnb/react-dates/blob/master/src/components/DayPicker.jsx#L77?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:12
- Comments:19 (4 by maintainers)
Top GitHub Comments
I have the following setup:
A page with a list of ranges to select (This Month, Previous Month, Previous Year, etc.) and a DayPickerRangeController component, since you can also manually select these dates. So let’s suppose today is October 23rd, so I go back 3 months to July in the calendar, when I click on the “This Month” range the present month is selected, so October 1st through October 31st.
However the calendar is still showing July. I wouldn’t necesarily need it to change automatically, but there should at least be a way to pass in a “currentMonth” prop, with a “onChangeMonth” function to manipulate it from a parent. Is that possible?
@orouz yes but only by using my own fork