react-dates: Cannot indicate which month is visible on open
Ideally this should be a controlled prop that would default to the current month. That way you can close the <DayPicker /> and reopen to where you were previously
My vision is that this would be a currentMonth prop on the SingleDatePicker and on the DateRangePicker that would take in a moment object. If a parent component wanted to keep track of this in the state then, they could do so using the onPrevMonthClick and onNextMonthClick callbacks.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 26 (16 by maintainers)
Commits related to this issue
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
- Add initialVisibleMonth fn prop to DayPicker Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set th... — committed to rocketrip/react-dates by deleted user 8 years ago
I think that the fine tuned control of this prop allows for behavior like:
I think that while in a lot of cases, it makes sense to open to the start date month, we want to be able to cover all options easily, especially those cases where no date has been selected.
On Fri, Aug 19, 2016, 10:29 AM jcreamer898 notifications@github.com wrote:
@sag1v You can access to the currentMoment state (moment object) in your parent component by adding a ref to the date component
this.dayPicker.state.currentMonthDay picker implementation with ref and prev/next callbacks.
But at this moment, currentMonth hasn’t yet been updated (+/- 1 month) because the callback method is called before updating the state value.
@majapw Is there a better way to get this value without adding or removing 1 month manually like I did ?
callback method call (called before state update) DayPicker.jsx#L543 and finally, the state update of currentMonth DayPicker.jsx#L567
@majapw i know this is an oldie but can’t find it in the docs. so basically can we get the current month with
onClickNextMonthoronClickPrevMonth? i only get the click event when using these functionsSince this initial problem is solved by #70, I’m going to close this and move discussion on making the visible month a fully controlled prop to https://github.com/airbnb/react-dates/issues/48.
Thanks!
@majapw I think its working as expected, just carelessness on my end 😃
I’ll reopen the PR once https://github.com/airbnb/react-dates/pull/32 goes through and I can run
mountenzyme testsI feel like that should be on the parent component to guarantee, not on the DRP/SDP itself and so these should maybe be two separate changes.
On Thu, Aug 18, 2016, 6:46 PM Travis Bloom notifications@github.com wrote:
Hmmm, I feel like it should be either explicitly defined or it should be the present month. I think that maybe it’s not transparent enough behavior if we fall back to the selected date (plus with the
DateRangePicker, do you usestartDate?endDate? I think we probably wantvisibleMonthOnOpen || moment().startOf('month')Ya, I was concerned that if currentMonth was a prop the parent owned after showing it would mess up all the animation goodness.
Agree with calling it
visibleMonthOnOpen. If there is a date passed to the component, do you want to use that as the default month as a backup?Order I’m envisioning: month showing on mount goes
visibleMonthOnOpen || date || moment().startOf('month')?