javascript - 避免在单击内部元素时隐藏下拉菜单 [react-bootstrap]

标签 javascript reactjs bootstrap-4 react-bootstrap

我想通过单击下拉机器人内部的元素来隐藏它。我正在寻找通过 JQuery 来做到这一点的方法。有没有办法只使用 JavaScript 和react-bootstrap 来做到这一点?

我在 onBlur 上调用以下函数:

hideButtons(e){
    console.log("We here!", e.target.id)
    if(e && e.relatedTarget){
        e.relatedTarget.click();
    }
    this.setState({showAccountButtons: false},()=>{
        console.log(this.state.showAccountButtons)
    });
}  

最佳答案

React-bootstrap 有一个支持回调的 onSelect 。因此,只需在回调中执行您需要执行的操作即可。

https://react-bootstrap.github.io/components/dropdowns/

根据您问题中的可用信息,看起来执行以下操作就足够了。

hideButtons(e){
    this.setState({showAccountButtons: false},()=>{
        console.log(this.state.showAccountButtons)
    });
}
<Dropdown onSelect={hideButtons} .../>

如果不起作用请发表评论,并用更多信息更新您的问题,如果需要,我会更新答案

关于javascript - 避免在单击内部元素时隐藏下拉菜单 [react-bootstrap],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61093200/

相关文章:

php - Laravel 7 Yajra 数据表没有响应

jquery - 错误: Path does not match the corresponding path on disk

javascript - 幻灯片问题

javascript - jQuery Mobile 未刷新 Backbone.js 支持的列表( ListView (‘refresh’))

reactjs - 使用 React 钩子(Hook)触发具有副作用的事件,例如 onClick() 调用 fetch()

javascript - 在 onPress React Native 中传递 Props 和 Function

javascript - 如何访问 Cypress 的 React 组件

css - 将 SASS 变量设置为 CSS3 变量会导致 Bootstrap 4 出错

javascript - 如何在隔离范围内使用 $index ?

javascript - OpenAI API错误: "Module ' openai' has no exported member 'Configuration' "