[英]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.