简体   繁体   English

DateRangePicker反应日期使endDate不可单击

[英]DateRangePicker react-dates make endDate not clickable

In DateRangePicker, there's a start date and an end date. 在DateRangePicker中,有一个开始日期和一个结束日期。 What I want to achieve is if the user clicked on the end date while the start date is null, do not allow him to choose the end date first, because it will introduce 2 kind of selection which can lead to confusion. 我要实现的是,如果用户在开始日期为空时单击结束日期,则不要让他先选择结束日期,因为这会引入两种选择,这可能会引起混淆。

I tried this, 我试过了

onFocusChange={focusedInput => {
  let focusedInputTemp = focusedInput;
  if (!this.state.startDate && focusedInput === "endDate") {
    focusedInputTemp = "startDate";
  }
  this.setState({ focusedInput: focusedInputTemp });
}}

force focusInput to be startDate if endDate is selected and if startDate is null 如果选择了endDate并且startDate为null,则将focusInput设置为startDate

But then the behaviour seems break, do I missed something? 但是然后行为似乎中断了,我错过了什么吗? The demo is here https://codesandbox.io/s/jpom95rw8w 该演示在这里https://codesandbox.io/s/jpom95rw8w

You may set endDate as disabled when startDate is not filled. 当未填充startDate时,可以将endDate设置为禁用。 Just add the prop disabled={!this.state.startDate && "endDate"} to DateRangePicker . 只需将prop disabled={!this.state.startDate && "endDate"}DateRangePicker即可

Live demo: https://codesandbox.io/s/1o4vqp2qll 现场演示: https : //codesandbox.io/s/1o4vqp2qll

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

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