【问题标题】:How to use shouldSelect on Hint for React-Bootstrap-Typeahead to detect "enter" and "," keystrokes如何在 React-Bootstrap-Typeahead 的 Hint 上使用 shouldSelect 来检测“enter”和“,”击键
【发布时间】:2020-05-31 02:20:44
【问题描述】:

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

【问题讨论】:

    标签: react-bootstrap-typeahead


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2017-12-11
      • 2010-11-02
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多