reactjs - 有没有办法在 React Bootstrap Typeahead 中挂钩键盘菜单导航或选择?
问题描述
我正在使用 React Bootstrap Typeahead 来浏览一组树数据。每棵树都有一个我需要访问的 id,但我不希望它成为 labelKey。
我试过绑定 onFocus,但菜单项似乎从来没有获得它。onClick 工作正常,但我也需要支持键盘导航。将 onKeyPress 添加到菜单项似乎没有任何作用。
任何帮助表示赞赏。提前致谢。
以下是相关代码:
<Typeahead
filterBy={filterByFields}
id='typeahead-search'
labelKey={(option) => `${option.scientific_name}`}
onInputChange={this.startSearch} // fills props.suggestions
options={this.props.suggestions ? this.props.suggestions : []}
placeholder="Enter a tree name"
renderMenuItemChildren={(option) => (
<div
<!--this is the data I need -->
data-tree-id={option.tree_id}
onClick={this.dropdownClickHandler}
>
<div>
<span>
{option.scientific_name}
</span>
</div>
<small>
<span>
{option.common_name}
</span>
</small>
</div>
)}
/>
解决方案
推荐阅读
- javascript - postcss 插件是否应该将 postcss 引用为对等依赖项?
- c# - 调整 Excel FormulaArray 范围的大小以显示所有数据
- xml - 如何将工具提示添加到我的自定义 Excel 功能区 UI?
- generics - 如何扩展'T?
- javascript - heroku 环境变量返回未定义
- go - 为什么 Golang 不能下载某些网页?
- makefile - 为什么makefile中没有扩展变量?
- c++ - Winsock 数据不是从 IP 检索的,而是从普通 URL 检索的
- javascript - 如何使用线程逐行读取文件?
- flowtype - 如何使用 Flow 从对象中获取键及其类型的列表