0

I'm trying to implement a dropdown list in HTML/CSS and more specifically in React. I've found a tutorial here showing something that could interest me : Link

The only problem is that when I include this code and modify it a little in my React project nothing appends... It seems to be a problem of bootstrap but I can't identify it.
Here is what happens :
enter image description here

Here is my code :

import React, { Component } from "react";
import "./VerticalDots.css";


export default class VerticalDots extends Component {

  render() {
    return (
      <div class="btn-group">
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          <img src={require("../imgs/3dots-vertical.png")} alt="NotFound"/>
        </button>

        <ul class="dropdown-menu">
          <li>0123 4567 8912 3456</li>
          <li>0123 4567 8912 3456</li>
          <li>0123 4567 8912 3456</li>
        </ul>
      </div>
    );
  }
}

A little help would be much appreciated !

2
  • the ul should also have aria-labelledby="dropdownMenuButton" with the name dropdownMenuButton the same as the id of your button check it here Commented Jul 30, 2019 at 18:02
  • Did you require bootstrap.js and bootstrap.css in your project? Do you see any error in the console? Commented Jul 30, 2019 at 18:04

2 Answers 2

3

It seems you are not loading Bootstrap's assets. In the codepen you linked, you can see that, under "Settings > CSS" and "Settings > JavaScript", Bootstrap is required.

To load them, you must import them from your bundle, for instance if you use webpack, in App.js

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';

Another option is to use a CDN, like Codepen does, but you probably want the above for a production build.

Sign up to request clarification or add additional context in comments.

Comments

1

Solved by adding :

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';

1 Comment

Rather than post how you solved it as an "answer", you should accept Matthieu Libeer's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.