【问题标题】:Is there a way to find whether the user opened the select field and did not select any option and closed the select field in React有没有办法查找用户是否打开了选择字段并且没有选择任何选项并关闭了 React 中的选择字段
【发布时间】:2021-10-22 12:16:13
【问题描述】:

我正在使用 React.js 并使用 Material.ui 中的 Select 组件。当用户打开选择并关闭它而不选择任何选项时,我想抛出错误。我不想在页面渲染开始时抛出错误。我尝试在构建道具中使用 onClose。

【问题讨论】:

    标签: reactjs select oncloselistener


    【解决方案1】:

    您可以使用所选选项的状态:

    const [selectedOption, setSelectedOption] = useState(null);

    然后,在关闭事件中检查 selectedOption 是否仍为 null 并引发错误。当然你还需要设置用户点击选项时的状态。

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      相关资源
      最近更新 更多