0

我已经尝试了从React Datepicker禁用当前日期的可能方法。

下面是我的代码。

<SingleDatePicker
  showDefaultInputIcon
  inputIconPosition={ICON_AFTER_POSITION}
  date={input.value}
  placeholder="Move Date"
  numberOfMonths={input.numberOfMonths ? input.numberOfMonths : 1}
  focused={meta.active}
  openDirection="up"
  onDateChange={value => {
    const val = value && value.format ? value.format() : value;
    input.onChange(val);
  }}
  onFocusChange={({ focused }) => {
    if (focused) {
      input.onFocus({ focused });
      return;
    }
    input.onBlur();
  }}
/>

如果有人禁用帮助我。

4

1 回答 1

0

终于可以通过使用isOutsideRangeprop 和moment.

下面是我更新的代码。
我首先创建了明天的日期。

const tomo = moment().add(1, 'day').endOf('day');

我只启用了从明天开始使用的日期isOutsideRange

 <SingleDatePicker
  showDefaultInputIcon
  inputIconPosition={ICON_AFTER_POSITION}
  date={input.value}
  placeholder="Move Date"
  numberOfMonths={input.numberOfMonths ? input.numberOfMonths : 1}
  focused={meta.active}
  openDirection="up"
  isOutsideRange={day => !isInclusivelyAfterDay(day, tomo)}
  onDateChange={value => {
    const val = value && value.format ? value.format() : value;
    input.onChange(val);
  }}
  onFocusChange={({ focused }) => {
    if (focused) {
      input.onFocus({ focused });
      return;
    }
    input.onBlur();
  }}
/>
于 2017-12-26T11:12:42.603 回答