arfedulov / semantic-ui-calendar-react

Datepicker react component based on semantic-ui-react components
https://arfedulov.github.io/semantic-ui-calendar-react/
MIT License
260 stars 92 forks source link

Calendar Crashes when minDate and maxDate are used with dates in the past #127

Open olliebobster opened 5 years ago

olliebobster commented 5 years ago

Bug: When minDate and maxDate are both used for dates in the past, the calendar crashes on opening.

To Reproduce

  1. Initialise a new DateInput object
  2. Set the minDate to {Moment("2019-03-01")}
  3. Set the maxDate to {Moment("2019-03-29")}
  4. Launch App and attempt to click the Calendar input field.

Expected behavior The calendar should open with the correct min and max date range, but have no date selected.

Dependencies versions Provide version numbers of following packages:

arfedulov commented 5 years ago

We need to know on which month to open a calendar. By default it opens on current month. You have an option to set initialDate on DateInput. For example, if you set initialDate={moment('2017-01-01')}, popup will open on Jan 2017. You can circumvent this error by setting meaningful initialDate (inside [minDate, maxDate] interval).

I will probably fix it by computing default initial date depending on given minDate and maxDate.

sevketriza commented 5 years ago

We need to know on which month to open a calendar. By default it opens on current month. You have an option to set initialDate on DateInput. For example, if you set initialDate={moment('2017-01-01')}, popup will open on Jan 2017. You can circumvent this error by setting meaningful initialDate (inside [minDate, maxDate] interval).

I will probably fix it by computing default initial date depending on given minDate and maxDate.

initialDate was not fix problem, we use value attribute by default may be it overrides initialDate's value.

SarasArya commented 5 years ago

I can confirm initialDate doesn't fix the problem, maybe, if can somehow travel to the minDate month, probably there selectable[0].position will have at least one value, so that it doesn't crash.

 if(selectable[0] === undefined)
 { check if we have a minDate or maxDate Property if yes month = minDate(month) and selectable[0] = minDate
arfedulov commented 5 years ago

Fixed in #140.

@sevketriza Yes, value prop has precedence over initialDate. Value is parsed and start date is used as initialDate. So when you have value that doesn't fit maxDate or minDate you get an error.

shahbaz-github commented 4 years ago

I am getting the same issue in DateInput on maxDate & minDate. I can able to set initialDate first time only after reset i can't set initalDate.

Kindle do the needful.