如何使用 shouldSelect on Hint for React-Bootstrap-Typeahead 来检测"enter"和","击键



我一直在试图找出一种方法来选择"Enter"或","击键的提示,但找不到任何文档。此外,我在编译期间收到以下警告"警告:[反应引导类型提前]selectHintOnEnter道具已弃用。使用Hint组件上的shouldSelect道具来定义哪些击键可以选择提示。有没有关于如何在"提示"上使用应该选择的例子?

shouldSelectprop 具有以下签名:

(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

最新更新