prabeen90
prabeen90

Reputation: 450

keep the keyboard open on click outside of the keyboard area, javascript

Keyboard opens on focus of an input.

and there is a button on the page which basically mute/unmute the app.

while keyboard is opened when I clicked the Button the keyboard got dismissed,

I don't want the keyboard to get dismissed on Button click,

I tried e.stopPropagation) on Button click, and keyboard still got dismissed.

Is it possible to achieve this behaviour.

Upvotes: 0

Views: 1506

Answers (1)

Steve P Sajeev
Steve P Sajeev

Reputation: 66

I came up with a pure javascript solution. You have to listen for the blur event on the input field. When ever the input field is blurred, immediately call the focus function. This will bring back the focus on to the input field.

Here the input field is given the id input

Javascript:

var t = document.getElementById("input");
t.addEventListener("blur", (e)=>{
    t.focus()
})

The only way to close the keyboard is to press the back button. Pressing anywhere else on the screen wont close the keyboard.

Upvotes: 3

Related Questions