[英]How to prevent react-dates SingleDatePicker to open on focus?
I'm using react-dates SingleDatePicker.我正在使用 react-dates SingleDatePicker。 The visibility of the calendar is controlled by the focused prop.日历的可见性由focused prop控制。 When using tabs on the website, I don't want the calendar to open, I want it to open on enter key.在网站上使用选项卡时,我不想打开日历,我希望它在输入键时打开。 Is there a way to achieve this?有没有办法实现这一目标? Thanks!谢谢!
You should to control "focused" property and onFocusChange method.您应该控制“focused”属性和 onFocusChange 方法。 Also set the listener to container.还将侦听器设置为容器。 For example例如
.....
const [focusedInput, setFocusedInput] = useState(null);
const handleUserKeyPress = (evt) => {
if (evt.keyCode === 13 && !evt.shiftKey) setFocusedInput(true);
};
....
<div onKeyUp={handleUserKeyPress}>
<SingleDatePicker
focused={focusedInput}
onFocusChange={({ focused }) => {
const focus = focusedInput && focused ? true : false;
setFocusedInput(focus);
}}
.....
/>
</div>
.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.