[英]How to focus on a Material UI Button while Enter key pressing
在最后一个输入中按 Enter 时,您需要使用ref
来聚焦按钮:
Firest,创建参考:
const buttonRef = useRef(null);
然后,在按钮中添加 ref:
<button ref={buttonRef} ...>
之后,在最后一个输入中添加onKeyPress
以检查按Enter
:
<input onKeyPress={handleKeyPress} ...>
Anh 这是handleKeyPress
:
const handleKeyPress= e => {
if(e.key === "Enter"){
buttonRef.current.focus()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.