Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Any help here would be appreciated!

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading