react-component / calendar

React Calendar
http://react-component.github.io/calendar/
MIT License
1.7k stars 494 forks source link

Providing an array in selectedValue or defaultSelectedValue for rc-calendar #506

Open oskarleonard opened 5 years ago

oskarleonard commented 5 years ago

I want to select multiple dates programmatically since i have a "filter" for week view and day view. So when in week view i would like to select that whole week.

I tried to pass in an array of dates to selectedValue (as one can do for ´RangeCalendar) toCalendarand got an undocumented behavior. It seemed to select the dates in the arrat (not acting like a range), so if i passed inselectedValue={[moment("2019-02-16"), moment("2019-02-20")]}`, the dates 2019-02-16 and 2019-02-20 was selected (not the dates in between). This is all good and i can modify it to my needs using this prop, hover im getting

Warning: Failed prop type: Invalid prop `defaultSelectedValue` of type `array` supplied to `CalendarMixinWrapper`, expected `object`.

Which makes me think either this is not really supported and will lead to bugs

mdelrossi1 commented 5 years ago

@oskarleonard I don't know why you are getting that error without seeing more of your code, but to get the range selected, have you tried something like this?

const selectedStartDate = moment("2019-02-16")

...
selectedValue={[selectedStartDate, selectedStartDate.clone().add(7, 'days')]}
...