CSS: Bootstrap DropDown From Text Click

(Last Updated On: )

In this tutorial I will show you how how to use bootstrap with React/Node to make a dropdown from a text or image on click using just bootstrap.

You will need bootstrap and jquery.

  1. npm install bootstrap@3.3.7 --save
  2. npm install jquery@3.2.1 --save
  3. npm install file-loader --save
  4. npm install url-loader --save

You will also need to update webpack.config.js and add the following under “loaders”.

  1. { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" },
  2. { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
  3. { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
  4. { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/octet-stream" },
  5. { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=image/svg+xml" }

Next you need to require bootstrap and jQuery.

  1. window.jQuery = window.$ = require("jquery");
  2. require("bootstrap");

You will need to also require the bootstrap css.

  1. require("bootstrap/dist/css/bootstrap.min.css");

The following is all you then need to display a css like dropdown.

  1. <div className="btn-group" >
  2. <a className="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">testHeading</a>
  3. <ul className="dropdown-menu">
  4. <li>My Value</li>
  5. </ul>
  6. </div>