Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Dropdown is not working in React

I include a dropdown button to React from bootstrap Dropdowns, But it is not working and shows as a normal button. Can you give me a solution for this?

<div className="dropdown">
    <button className="btn btn-secondary 
                 dropdown-toggle" 
                 type="button" 
                 id="dropdownMenuButton"
                 data-toggle="dropdown"
                 aria-haspopup="true" 
                 aria-expanded="false">
                 Dropdown button
    </button>
            <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
                <a className="dropdown-item" href="#">Action</a>
                <a className="dropdown-item" href="#">Another action</a>
                <a className="dropdown-item" href="#">Something else here</a>
            </div>
</div>

The output is a normal button like this. enter image description here

like image 943
Pulsara Sandeepa Avatar asked Apr 19 '20 13:04

Pulsara Sandeepa


People also ask

Why is my bootstrap dropdown not working in react?

Why is my drop down menu not working in bootstrap? Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.


1 Answers

Dropdowns are not working without popper.js and jquery.js.

So please install popper.js and jquery.js in your system using npm install popper.js jquery --save and don't forget to include it.

With CDN

https://stackblitz.com/edit/create-react-class-m3qfxu?file=index.html

With NPM

https://stackblitz.com/edit/create-react-class-xvsthx?file=index.js

like image 200
Nisharg Shah Avatar answered Sep 28 '22 18:09

Nisharg Shah