question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap Dropdown does not work

See original GitHub issue

Hi, I’m Trying to use the Dropdown menu in SiteNavi/Index.jsx and it doesn’t seem to be working.

render() {
    const pathPrefix =
      process.env.NODE_ENV === 'development' ? '' : __PATH_PREFIX__
    const { location, title } = this.props
    return (
      <nav className="navbar navbar-toggleable-md navbar-light bg-faded">
  <button className="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span className="navbar-toggler-icon"></span>
  </button>
  <a className="navbar-brand" href="#">Navbar</a>
  <div className="collapse navbar-collapse" id="navbarNavDropdown">
    <ul className="navbar-nav">
      <li className="nav-item active">
        <a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a>
      </li>
      <li className="nav-item">
        <a className="nav-link" href="#">Features</a>
      </li>
      <li className="nav-item">
        <a className="nav-link" href="#">Pricing</a>
      </li>
      <li className="nav-item dropdown">
        <a className="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <div className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <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>
      </li>
    </ul>
  </div>
</nav>
    )
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
drmikecrowecommented, Mar 26, 2019

For those who are still trying to solve this, here’s the solution I used: In gatsby-node.js do:

// https://github.com/gatsbyjs/gatsby/issues/6053#issuecomment-457243520

const webpack = require('webpack')

exports.onCreateWebpackConfig = ({ stage, rules, loaders, plugins, actions }) => {
  if (stage === 'build-html') {
    actions.setWebpackConfig({
      module: {
        rules: [
          {
            test: require.resolve('bootstrap'),
            use: loaders.null()
          },
          {
            test: require.resolve('jquery'),
            use: loaders.null()
          }
        ]
      }
    })
  }
  actions.setWebpackConfig({
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: 'popper.js',
        Bootstrap: 'bootstrap.js'
      })
    ]
  })
}
3reactions
wsaboriocommented, Dec 13, 2017

Was really racking my brain over this dropdown for a long time and easiest fix for me ended up being upgrading to the latest Bootstrap beta + including Popper.js in html.js (didn’t go the webpack route) as there’s a new dependency on it specifically for dropdowns.

You can read more here: https://getbootstrap.com/docs/4.0/getting-started/introduction/#js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap dropdown does not work - Stack Overflow
I'm starting to experiment with Bootstrap, but I'm not able to get the js dropdown function working the way it does in their...
Read more >
[Solved]-Bootstrap dropdown not working - Studytonight
The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute...
Read more >
Can't get bootstrap dropdown working - CodeProject
If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are...
Read more >
Dropdowns · Bootstrap v5.0
Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They're made interactive with the included Bootstrap dropdown JavaScript ...
Read more >
Bootstrap dropdown button not working on click || Solved 2022
In this video, you can easily solve bootstrap dropdown button not working on click .भाई प्लीज सब्सक्राइब करना ना ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found