onKeyDown event not working on divs in React

前端 未结 7 1132
北恋
北恋 2020-12-02 11:11

I want to use a keyDown event on a div in React. I do:

  componentWillMount() {
      document.addEventListener(\"keydown\", this.onKeyPressed.bind(this));
          


        
7条回答
  •  执笔经年
    2020-12-02 11:42

    The answer with

    works for me, please note that the tabIndex requires a number, not a string, so tabIndex="0" doesn't work.

提交回复
热议问题