[英]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.