简体   繁体   中英

Add a maximum number of days with react-dates

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

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}
/>

 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; }) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM