如何在应使用HintSelect上使用React-Bootstrap-Typeahead来检测“ enter”和“,”击键

问题描述 投票:0回答:1

我一直在试图找到一种方法来选择“ Enter”或“,”击键的提示,但是找不到任何文档。此外,在编译期间,我收到以下警告:“警告:[react-bootstrap-typeahead] selectHintOnEnter道具已过时。使用shouldSelect组件上的Hint道具定义可以选择提示的击键”。是否有关于如何在“提示”上使用shouldSelect的示例?

react-bootstrap-typeahead
1个回答
0
投票

shouldSelect道具具有以下签名:

(shouldSelect: boolean, SyntheticKeyboardEvent<HTMLInputElement>) => boolean

您可以使用它来定义应该选择提示的条件。在您的情况下,您需要以下内容:

<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

© www.soinside.com 2019 - 2024. All rights reserved.