Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't detect enter press on mobile (textarea)

To detect enter press I'm using simple solution:

if (e.keyCode == 13) {
    // do something
}

On desktop it works properly anywhere. On tablet, smartphone - too - but, if it comes to textarea this doesn't work.

It became a problem since few last chrome updates.

So, when you press enter from mobile you see just new line "\n", but no function execution.

So, how to detect enter on textarea on mobile devices on latest chrome version?

like image 625
Oleksii Shnyra Avatar asked Oct 18 '22 14:10

Oleksii Shnyra


1 Answers

if like me you are using react, onKeyPress={e => e.key} works.

e.key returns "Enter" on browser and mobile

e.code returns "Enter" on browser only

like image 88
noreply Avatar answered Oct 30 '22 03:10

noreply