stephy / CalendarPicker

CalendarPicker Component for React Native
803 stars 373 forks source link

initialDate prop does not show the day in a month as selected #113

Closed adityafuture01 closed 4 years ago

adityafuture01 commented 6 years ago

When a date or moment object passed to initialDate prop, calendar does not show the day in a month as selected though it does show the month and year represented by the passed date or moment object.

Please fix it.

peacechen commented 6 years ago

Please read the documentation thoroughly. initialDate was never intended to select a date. Use selectedStartDate to select one.

adityafuture01 commented 6 years ago

The initialDate is used to show the date as selected when calendar opens second time. I'm using this prop to show the previously selected date if user opens the calendar second time. So, when user opens the calendar again it should show the previously selected date as default. Currently, the calendar shows the month and year of previously selected date but not the day.

peacechen commented 6 years ago

Inspect the source code and you'll see that initialDate does not select a date. It only sets the month & year. Have you tried using selectedStartDate ?

azabost commented 6 years ago

@peacechen selectedStartDate isn't passed from the props to the state so it doesn't work. A quick fix that makes it work may look like this: https://github.com/bright/CalendarPicker/commit/a4f6a8085a7f0c5f93e139e35185ea0c4f893404

peacechen commented 6 years ago

Thanks @azabost for pointing that out. The state should also be updated on a prop change in componentDidUpdate. Would be happy to review a PR that's been well tested.

peacechen commented 6 years ago

@adityafuture01 @azabost PR #123 passes selectedStartDate to state and updates on prop change. Would you test if this is working correctly for you?