有一个CustomCalendarComponent
用途react-datepicker
如下所示:
constructor(props) {
super(props)
this.state = {
start :new Date()
}
this.handleStartChange = this.handleStartChange.bind(this);
}
handleStartChange (start) {
start = start || this.state.start;
this.setState({ start })
};
render() {
return(
<>
<span>Start</span>
<DatePicker
selected = {this.state.start}
selectsStart
startDate = {this.state.start}
endDate = {this.state.end}
onChange = {this.handleStartChange}
customInput = { <CustomCalendarComponent />}
dateFormat = "dd/MM/yyyy"
openToDate = {this.state.start}
showMonthDropdown
showYearDropdown
dropdownMode = 'select'
/>
</>
)
}
它有一个customInput
如下所示:
constructor(props){
super(props)
}
static propTypes = {
onClick: PropTypes.func,
onChange: PropTypes.func,
value: PropTypes.string,
placeholderText: PropTypes.string
};
render() {
return (
<div>
<FormGroup className="mb-0">
<InputGroup>
<Input
className={this.props.className}
placeholder={this.props.placeholder}
onClick={this.props.onClick}
value={this.props.value}
onChange={this.props.onChange}
type="input"
/>
<InputGroupAddon addonType="prepend">
<InputGroupText
className="dateIconStyle"
onClick={this.props.onClick}
>
<i className={"icon-calendar"} />
</InputGroupText>
</InputGroupAddon>
</InputGroup>
</FormGroup>
</div>
);
}
只要用户从日历中选择日期,一切都很好,当用户尝试输入日期时,它不起作用。当用户开始删除输入时,它无法正常工作。试了很多,花了将近一整天,还是找不到问题,我在github上找到了这个问题,但是没有运气,是什么问题?