watthecode
watthecode

Reputation: 101

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

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.

Upvotes: 3

Views: 5527

Answers (1)

evgeni fotia
evgeni fotia

Reputation: 4810

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();
    }
}

Upvotes: 9

Related Questions