首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对React-Bootstrap-Typeahead的提示使用shouldSelect来检测"enter“和",”击键

如何对React-Bootstrap-Typeahead的提示使用shouldSelect来检测"enter“和",”击键
EN

Stack Overflow用户
提问于 2020-05-30 05:50:06
回答 1查看 404关注 0票数 2

我一直试图找出一种方法来选择"Enter“或",”击键时的提示,但找不到任何有关它的文档。此外,在编译过程中,我收到以下警告:" warning : react-bootstrap-typeahead selectHintOnEnter属性不推荐使用。在Hint组件上使用shouldSelect属性来定义哪些击键可以选择提示。“有没有关于如何在“提示”上使用shouldSelect的例子?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-31 02:20:44

shouldSelect属性具有以下签名:

代码语言:javascript
复制
(shouldSelect: boolean, SyntheticKeyboardEvent<HTMLInputElement>) => boolean

您可以使用它来定义应在哪些条件下选择提示。在您的例子中,您需要类似于以下内容:

代码语言:javascript
复制
<Hint
  shouldSelect={(shouldSelect, e) => {
    // Select the hint if the user hits 'enter' or ','
    return e.keyCode === 13 || e.keyCode === 188 || shouldSelect;
  }}>
  ...
</Hint>

下面是一个有效的示例:https://codesandbox.io/s/rbt-shouldselect-example-51s7n

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62095090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档