【发布时间】:2020-08-13 04:46:55
【问题描述】:
我正在尝试将DayPickerInput 与我自己的自定义输入一起使用,但是在键入输入时,一旦选择了一天,就会失去焦点。如果尝试输入例如:2020-08-20,则可以看到这一点,当输入到达“2020-08-2”时,它会选择 2nd 作为日期并取消输入焦点,不允许用户到达 20。
Here 是一个代码沙箱,我在其中复制了问题。
DayPickerInput的用法:
<DayPickerInput
component={(props) => <CustomInput {...props} />}
value={value}
onDayChange={setValue} />
还有我的自定义输入组件:
import React from "react";
class Input extends React.Component {
constructor(props) {
super(props);
this.inputRef = React.createRef();
}
focus() {
this.inputRef.current.focus();
}
render() {
return <input {...this.props} ref={this.inputRef} />;
}
}
export default Input;
我已经看到this 问题,并尝试了那里的解释,但它不起作用,我不知道还能尝试什么。
感谢任何指导!谢谢!
【问题讨论】:
-
你可以尝试将“hideOnDayClick={false}”作为道具添加到 DayPickerInput 中,这样可以让它保持打开状态
-
添加
hideOnDayClick并没有改变任何东西,因为覆盖层之前仍处于打开状态,只是从输入中失去焦点