React-dates: Selected dates not painted when load more months

Created on 7 Sep 2017  路  5Comments  路  Source: airbnb/react-dates

Hi, i couldn't find the issue so i don't know if it's a known issue.

When you open the datepicker in mobile vertically and you load more months it doesn't paint when you select the date.

The same error is present in airbnb.com when you visit with mobile:

In this image you can see how it paint when i select the first date in the months loaded at begining:
seleccion_031

And here you can see how it doesn't paint when i select a date in a month that was loaded after
seleccion_032

bug

Most helpful comment

Hi @majapw,
I did some digging here, and found that the problem is related to this condition:

addModifier(updatedDays, day, modifier) {
    ....
    if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
      return updatedDays;
    }

isDayVisible is not considering the number of visible months in the calculation to validate the date.

Adding something like numberOfMonths = Object.keys(visibleDays).length; a couple of lines above fixes this particular problem but problably there is a better aproach to avoiding overriding a prop (seems hacky to me).
Example:

    if (orientation !== VERTICAL_SCROLLABLE) {
      currentMonth = currentMonth.clone().subtract(1, 'month');
      numberOfMonths += 2;
    } else {
      numberOfMonths = Object.keys(visibleDays).length;
    }
    if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
      return updatedDays;
    }

I checked the tests and adding this doesn't break anything but didn't submit a PR yet.

All 5 comments

Yup! Need to fix the vertical scrollable datepicker. X_x

Hi @majapw,
I did some digging here, and found that the problem is related to this condition:

addModifier(updatedDays, day, modifier) {
    ....
    if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
      return updatedDays;
    }

isDayVisible is not considering the number of visible months in the calculation to validate the date.

Adding something like numberOfMonths = Object.keys(visibleDays).length; a couple of lines above fixes this particular problem but problably there is a better aproach to avoiding overriding a prop (seems hacky to me).
Example:

    if (orientation !== VERTICAL_SCROLLABLE) {
      currentMonth = currentMonth.clone().subtract(1, 'month');
      numberOfMonths += 2;
    } else {
      numberOfMonths = Object.keys(visibleDays).length;
    }
    if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
      return updatedDays;
    }

I checked the tests and adding this doesn't break anything but didn't submit a PR yet.

Hi @majapw,

Any updates on this one?

@majapw has this been fixed yet?

Is it fixed for DayPickerSingleDateController as well? I am still getting the same issue on [email protected].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maciej-w picture maciej-w  路  3Comments

krissalvador27 picture krissalvador27  路  3Comments

thomasdtucker picture thomasdtucker  路  3Comments

jpollard-cs picture jpollard-cs  路  3Comments

arthurvi picture arthurvi  路  3Comments