In Regular React how to dismiss mobile keyboards on submit or 'enter' key?

南楼画角 提交于 2021-02-10 17:28:45

问题


I am trying to find this answer, but all the other questions I have found are React Native.

`handleEnter(e){
    if(e.key == 'Enter'){
        //REMOVE KEYBOARD
    }
}`

Also my input is a text search. So I want the keyboard to hide so users can see the results that come up.


回答1:


e.target is the focused input or textarea where the user is writhing. When he click on Enter the focused input became unfocused and so the keyboard disappear

`handleEnter(e){
    if(e.key == 'Enter'){
        e.target.blur();
    }
}`


来源:https://stackoverflow.com/questions/53006913/in-regular-react-how-to-dismiss-mobile-keyboards-on-submit-or-enter-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!