Search code examples
reactjsreact-day-picker

React Day Picker: How to disable interaction with disabled dates in "Select Multiple dates"


How can I disable click on dates in "Selecting multiple dates".

Inside my render,

<DayPicker selectedDays={this.state.selectedDays} onDayClick={this.handleMultiDayClick} disabledDays={{ before: this.state.currentDay }} />

I am able to disable days but if I click on disabled dates then they are also added in the state.

I would appreciate the help.


Solution

  • Can you not simply check for disabled dates in your onclick handler and exclude the disabled dates from your selectedDays state object?

    handleMultiDayClick(e) {
      // check here for disabled dates
      if(!disabledDate) {
        this.setState({selectedDays: this.state.selectedDays.push(newDate).slice(0)})
      }
    }