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?
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?
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.
react-select
no onKeyDown props available.
Consider something like this:
class App extends Component {
onKeyDown = () => {
console.log("your code here");
};
render() {
return (
<div onKeyDown={this.onKeyDown} className="App">
<Select options={options} />
</div>
);
}
}
codesandbox: https://codesandbox.io/s/react-select-key-event-khczpp
© 2022 - 2024 — McMap. All rights reserved.