简体   繁体   English

当用户使用 react-dates 输入过去的日期时,onDateChange 返回 null

[英]onDateChange returns null when user types a past date using react-dates

I'm using SingleDatePicker from react-dates and it works fine when selecting a date from the datepicker(even a past date), but when the user types a past date the onDateChange handler returns null, but when the user types a future date onDateChange returns a moment object.我正在使用react-dates SingleDatePicker ,它在从SingleDatePicker选择日期(甚至是过去的日期)时工作正常,但是当用户输入过去的日期时, onDateChange处理程序返回 null,但是当用户输入未来的日期时onDateChange返回一个时刻对象。

      <SingleDatePicker
        date={moment(Date.now())}
        focused={focused}
        displayFormat="MM/DD/YYYY"
        onFocusChange={() => setFocused(!focused)} 
        onDateChange={date => {
          console.log(date);
        }}
      />

Here's what i get when typing the current or future date and null is when typing a past date.这是我在输入当前或未来日期时得到的结果,而null是在输入过去日期时得到的。

来自 devtools 的屏幕截图

If you want to select past days, pass in isOutsideRange={() => false} prop.如果要选择过去的日子,请传入isOutsideRange={() => false}

source 来源

<SingleDatePicker
  date={moment(Date.now())}
  focused={true}
  displayFormat="MM/DD/YYYY"
  onFocusChange={() => true}
  onDateChange={date => {
    console.log(date);
  }}
  isOutsideRange={() => false}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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