【发布时间】:2021-10-03 10:17:41
【问题描述】:
我有一个下拉菜单,我想在选择某些内容时触发一个功能。
<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)}
/>
这是我的 onChange 函数
handleInput(e:any) {
let value = moment(e).format('MM/DD/YYYY');
this.props.onChange({
target: {
name: this.props.name,
value: value
}
});
this.setState({
inputValue: value,
datePickerIsOpen: false
})
}
我遇到的问题是,如果我选择已选择的选项,则不会触发该功能。我明白这是因为没有任何改变,但有没有办法解决这个问题?
【问题讨论】:
-
有人知道如何解决这个问题吗?
标签: reactjs typescript react-typescript