When I click on a single dropdown menu link in the navigation bar, all the dropdown menu links also show or display. How do I fix this by letting only one dropdown menu link show?
I have tried changing the id value that points to aria-labelledby
This is the state of my app
state = {
dropDown: false
};
handleDropdown = e => {
this.setState({ dropDown: !this.state.dropDown });
};
Inside the render function
render() {
const { dropDown } = this.state;
/*Conditional statement to select a class base on the state*/
const dropMenu = dropDown ? 'dropdown-menu show' : 'dropdown-menu';
/*The two dropdown menu list the displays(both) even when one is clicked*/
<li className="nav-item dropdown">
<Link
onClick={this.handleDropdown}
className="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Dropdown
</Link>
<div className={dropMenu} aria-labelledby="navbarDropdown">
<Link className="dropdown-item" to="#">
Action
</Link>
<Link className="dropdown-item" to="#">
Another action
</Link>
<div className="dropdown-divider" />
<Link className="dropdown-item" to="#">
Something else here
</Link>
</div>
</li>
<li className="nav-item dropdown">
<Link
onClick={this.handleDropdown}
className="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Dropdown
</Link>
<div className={dropMenu} aria-labelledby="navbarDropdown">
<Link className="dropdown-item" to="#">
Action
</Link>
<Link className="dropdown-item" to="#">
Another action
</Link>
<div className="dropdown-divider" />
<Link className="dropdown-item" to="#">
Something else here
</Link>
</div>
</li>
};