簡體   English   中英

如何避免在反應中使用 tabIndex 進行 OnKeyDown 捕獲事件?

[英]How to aovid using tabIndex for OnKeyDown catch event in react?

我有一個問題,因為我正在使用 react-windows 庫來制作新聞列表。

問題是我需要處理onKeyDown事件,因為需要在按鈕上添加tabIndex

但是當我添加tabIndex時,它會激活 react-widows 庫中的一些滾動行為。

如何在沒有tabIndex的情況下使用 handle onKeyDown and Up events

這是文檔的一個 div/按鈕:

<div
              className="card-content-wrapper"
              role="button"
              id={collectionId + id}
              onClick={() => handleClick && handleClick(id)}
              onKeyDown={(e) => handleKeyDownUp && handleKeyDownUp(e, index)}
            >

您可以管理按鍵事件

class SimpleExample extends React.Component {
    onKeyDown =(event)=>{
        console.log('keyCode',event.keyCode)
    }
    render() {
        return (
             <div>
      <input type="text" id="one" onKeyDown={this.onKeyDown} />
    </div>
        );
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM