1

I am trying to highlight the selected date on click of specific date using React-dates but didn't get any solution for it. I had used:

isDayHighlighted={day1 => returnDates().some(day2 => isSameDay(day1, day2))}

which works correctly to highlight dates. but for specific date how can i do this.

Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99
LB93
  • 117
  • 1
  • 12
  • what do you mean? selected date is highlighted by default – Sagiv b.g Nov 21 '18 at 07:36
  • oh really? In my case it is highlighted only on hover. – LB93 Nov 21 '18 at 08:06
  • you can see it in their [examples docs](http://airbnb.io/react-dates/?selectedKind=DateRangePicker%20%28DRP%29&selectedStory=default&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) – Sagiv b.g Nov 21 '18 at 08:08
  • I had used the SingleDatePicker component of react-dates – LB93 Nov 21 '18 at 08:09
  • same behavior, the only difference is that it is auto close after the selection (which you can control) – Sagiv b.g Nov 21 '18 at 08:13
  • Thanks for your help it works. somehow i am able to show selected date highlighted. but now once i select the date it is always showing selected even after clicking on next previous arrow of calendar. is there any way on-clicking outside the selected date can be deselected. – LB93 Nov 21 '18 at 11:43
  • you mean reset the selected date when navigating to different months? – Sagiv b.g Nov 21 '18 at 12:17

1 Answers1

1

If i understand correctly (based on your comments), you want to reset the selected date whenever the current displayed month is changed.

You can hook to onNextMonthClick and onPrevMonthClick and set the date to null.

Running example

class App extends React.Component {
  state = { date: null, focused: false };

  onDateChange = date => {
    this.setState({ date });
  };

  onFocusChange = ({ focused }) => {
    this.setState({ focused });
  };

  resetDate = () => {
    this.setState({ date: null });
  };

  render() {
    const { focused, date } = this.state;
    return (
      <div>
        <h1>React Dates Test</h1>
        <SingleDatePicker
          date={date}
          focused={focused}
          numberOfMonths={1}
          onDateChange={this.onDateChange}
          onFocusChange={this.onFocusChange}
          onNextMonthClick={this.resetDate}
          onPrevMonthClick={this.resetDate}
        />
      </div>
    );
  }
}
Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99