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