Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onKeydown event in react-select

I am using the react-select vserion 2 component. I want to be able to trigger the OnKeyDown event when someone presses the backspace key.

Does anyone know how to do this?

like image 355
pavanshinde Avatar asked Jul 31 '26 13:07

pavanshinde


1 Answers

react-select provides a prop onKeyDown which you can use as the following example:

 const onKeyDown = e => {
    // catch the code of the key pressed
    if (e.keyCode === 8) {
      // do your stuff
    }
  };

In this function you can catch the keyCode of the key pressed.

Here a live example.

like image 174
Laura Avatar answered Aug 03 '26 04:08

Laura



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!