如何在React中点击Bootstrap 5下拉菜单而不关闭它?

huangapple go评论60阅读模式
英文:

How can I click inside a bootstrap 5 dropdown without closing it, with React?

问题

我正在使用Bootstrap 5和ReactJS构建一个半复杂的导航栏,其中包括一个下拉菜单。

当我点击下拉菜单内的任何位置(即使我点击的部分只是纯文本而不是链接),下拉菜单都会关闭,我不知道为什么。我尝试添加了data-bs-auto-close属性,并将其设置为insideoutsidefalse,但似乎没有任何效果。

以下是我的问题的一个非常基本的代码示例 - 下拉菜单的左侧(其中只有一个小标题写着Hi)不应该触发关闭下拉菜单:

代码示例链接

在这里的任何帮助将不胜感激!

英文:

I'm building a semi-complex nav bar using with bootstrap 5 and ReactJS. For this, I'm using a dropdown menu.

When I click inside of the dropdown anywhere (even if the part I'm clicking on is just plain text and not a link), the dropdown closes and I have no idea why. I've tried adding the data-bs-auto-close prop and have set it to inside, outside and false and it doesn't seem to have any effect.

Here is a very basic code example of my problem - the left side of the dropdown (where it just has a small header saying Hi) shouldn't trigger the dropdown to close:

https://codesandbox.io/s/bootstrap-5-playground-forked-drrly7?file=/index.html

Any help here would be appreciated!

答案1

得分: 0

您正在使用旧版本的Bootstrap。请使用最新版本。它将起作用。我已在您的CodeSandbox中尝试过。
https://getbootstrap.com/docs/5.3/getting-started/introduction

英文:

You're using an old version of bootstrap. Use the latest version. It will work. I've tried in your codesandbox.
https://getbootstrap.com/docs/5.3/getting-started/introduction

huangapple
  • 本文由 发表于 2023年7月10日 23:03:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655043.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定