首页 > 解决方案 > 如何禁用今天的日期和日期选择器默认是第二天

问题描述

我正在尝试创建一个返回打开日期选择器的函数,它将返回今天日期的第二天,例如:今天的日期是 2021 年 10 月 1 日,所以第二天是 2021 年 10 月 2 日。

这是我的代码库:

  openToDate(val:any){

    console.log("val: ", val)
    return moment(val).toDate();
  }

        <DatePicker
          customInput={
            <React.Fragment>
              <input
                tabIndex={this.props.tabIndex}
                className="exact-date-input"
                placeholder={this.props.placeholder}
                autoComplete="off"
                type="text"
                maxLength={10}
                id="date-input"
                aria-label={ariaLabel}
                value={this.state.inputValue}
                onKeyDown={this.onKeyDownDateType}
                onClick={()=>this.openOrCloseDatePicker(true, this.state.error)}
                onFocus={()=>this.openOrCloseDatePicker(true, this.state.error)}
                onBlur={()=>this.emptyIfError(this.state.error)}
              />
            </React.Fragment>
          }
          openToDate={this.openToDate(this.props.value)}
          tabIndex={-1}
          selected={this.openToDate(this.props.value)}
          customInputRef="dateInput"
          autoComplete="off"
          id={this.props.id}
          onChange={this.handleInput}
          required={this.props.required}
          minDate={moment(today).toDate()}
          maxDate={moment(endRange).toDate()}
          open={this.state.datePickerIsOpen}
          onClickOutside={()=>this.openOrCloseDatePicker(false, this.state.error)}
        />

如何禁用今天的日期并自动选择第二天? 在此处输入图像描述

标签: javascriptreactjstypescript

解决方案


推荐阅读