2

I'm wondering if it's possible to add a maximum number of days to pick using react-dates. Basically the inverse of minimumNights property that already exists.

Cheers

Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99
Kup
  • 882
  • 14
  • 31

2 Answers2

5

You can use the isOutsideRange predicate prop.
You pass in a function that will set each date as available or not respectively to your maximum number of days variable.

Example:

const maximumDays = 6;
isOutsideRange = day => (
        focusedInput === END_DATE && (day.isBefore(startDate) || day.isAfter(startDate.clone().add(maximumDays, 'days')))
      );  

And then pass it to the component:

<DateRangePicker
  isOutsideRange={isOutsideRange}
  onDatesChange={this.onDatesChange}
  onFocusChange={this.onFocusChange}
  focusedInput={focusedInput}
  startDate={startDate}
  endDate={endDate}
/>
Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99
0

let fromRange = '29/03/2019';
let toRange = '30/04/2019';
const isOutsideRange = (day => {
    let dayIsBlocked = false;     
     if(day > moment(fromRange)) {
        dayIsBlocked = true;
    }     
    if(day > moment(toRange)) {
        dayIsBlocked = true;
    }    
    return dayIsBlocked;
})