How to deselect the input field when you click on the mobile keyboard (iOS)

I have not tested this on Android yet, but on iOS I know for sure that it does not work.

I have an input field where people can write material. I want to deselect (remove focus) the input field when someone pressed "enter" on the native iOS keyboard ... but it does not work. It just focuses on the input field, while I want to get rid of the focus on the input field.

I am using Angular / HTML / Ionic / pure JavaScript. I have many input fields, so I use classnames . Is there any way to achieve this?

enter image description here

Here you can see the input fields and keyboard below.

+5
source share
1 answer

You can simply listen to the keydown event in the input field and check if the keyCode event is 13 (key code for input). When this happens, you can simply call the blur() method of the input element.

It would look like this .

+5
source

Source: https://habr.com/ru/post/1264708/


All Articles