react-select 中的 onKeydown 事件

问题描述 投票:0回答:2

我正在使用react-select vserion 2组件。我希望能够在有人按下退格键时触发 OnKeyDown 事件。

有人知道该怎么做吗?

reactjs onkeydown react-select
2个回答
8
投票

react-select
提供了一个道具
onKeyDown
,您可以将其用作以下示例:

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

在此功能中,您可以捕获按下的按键的

keyCode

这里有一个实例


0
投票

react-select
没有可用的 onKeyDown 道具。

考虑这样的事情:

class App extends Component {
  onKeyDown = () => {
    // your code here ...
    console.log("your code here");
  };

  render() {
    return (
      <div onKeyUp={this.onKeyDown} className="App">
        <Select options={options} />
      </div>
    );
  }
}

codesandbox:https://codesandbox.io/s/react-select-key-event-khczpp

© www.soinside.com 2019 - 2024. All rights reserved.