7

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?

pavanshinde
  • 99
  • 1
  • 1
  • 4

1 Answers1

8

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.

Laura
  • 8,100
  • 4
  • 40
  • 50