I have modified a Bootstrap 4.5 navbar menu to function as a sidemenu. It is working properly, but I am facing an issue with the dropdowns within the menu. When I open one dropdown, it automatically closes another that was open previously. I want to allow users to open multiple dropdowns simultaneously.
Here is my current code:
$('a.dropdown-item').on('click', function(e){
e.stopPropagation();
});
$('a#navbarDropdown.nav-link.dropdown-toggle').on('click', function(e){
e.preventDefault();
});
//sidebar menu
var fixHeight = function() {
$('.navbar-nav').css(
'max-height',
document.documentElement.clientHeight - 150
);
};
fixHeight();
$(window).resize(function() {
fixHeight();
});
$('.navbar .navbar-toggler').on('click', function() {
fixHeight();
});
$('.navbar-toggler, .overlay').on('click', function() {
$('.mobileMenu, .overlay').toggleClass('open');
});
.sidebar-buttons img {
width: 30px;
height: 30px;
position: absolute;
top: 10px;
}
.sidebar-buttons #pin-button {
right: 10px;
}
.sidebar-buttons #home-button {
right: 50px;
}
.sidebar-buttons img:hover, .sidebar-buttons img:focus {
background: #555;
color: #fff;
}
input.star-button[type="checkbox"] {
content: url('assets/brand/star_empty_white.svg');
appearance: none;
display: inline-block;
width: 10px;
height: 10px;
margin-left: 10px;
}
input.star-button[type="checkbox"]:checked {
content: url('assets/brand/star_filled_white.svg');
}
.navbar {
height: 50px;
}
.navbar-brand img {
left: 50px;
top: 0;
width: 130px;
}
h1#header-text {
position: absolute;
right: 40%;
width: 190px;
}
.bg-darknavbar {
background: #15161A !important;
}
.dropdown-menu {
background-color: transparent;
}
.dropdown-item {
color: #fff;
padding: 0;
}
a.nav-link {
font-family: "Cera-PRO-Bold", Arial Black, Sans-serif !important;
font-size: 0.9375em;
}
a.dropdown-item {
font-family: "Cera-PRO-Regular", Arial, Sans-serif !important;
font-size: 0.75em;
}
.dropdown-item:hover, .dropdown-item:focus {
color: #fff;
background-color: transparent;
text-decoration: underline;
}
.nav-link.dropdown-toggle {
width: 240px;
border-bottom: 1px solid rgba(255, 255, 255, 1);
}
.dropdown-toggle::after {
float: right;
margin-top: 16px;
}
.navbar-collapse {
background-color: #15161A !important;
}
.mobileMenu {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
position: fixed;
top: 50px;
bottom: 0;
margin: auto;
left: 0;
-webkit-transition: all ease 0.25s;
transition: all ease 0.25s;
width: 300px;
background: #2E3138 0% 0% no-repeat padding-box;
opacity: 92%;
}
.mobileMenu.open {
-webkit-transform: translateX(0%);
transform: translateX(0%);
}
.mobileMenu .navbar-nav {
overflow-y: auto;
padding-left: 15px;
padding-top: 50px;
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-color: rgba(0, 0, 0, 0);
display: none;
}
.overlay.open {
display: block;
z-index: 1029;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14767b7b60676066756454203a213a27">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="66040909121512140716265248534855">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<nav class="navbar navbar-dark bg-darknavbar justify-content-sm-spacearound fixed-top">
<button class="navbar-toggler align-self-start" type="button"> <span class="navbar-toggler-icon"></span> </button>
<a class="navbar-brand" href="#"> LOGO </a>
<h1 id="header-text" class="text-white cera-pro d-none d-md-block">FLEET OFFICE</h1>
<div class="collapse navbar-collapse bg-dark p-3 p-lg-0 mt-lg-0 d-flex flex-column flex-lg-row flex-xl-row justify-content-lg-start mobileMenu"
id="navbarSupportedContent">
<ul class="navbar-nav align-self-stretch">
<li class="nav-item active"> <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> </li>
<li class="nav-item dropdown"> <a
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"> Contracts </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="http://www.google.com">View Contracts <input class="star-button" type="checkbox" /></a>
<a class="dropdown-item" href="#">Contracts Modifications <input class="star-button" type="checkbox" /></a>
<a class="dropdown-item" href="#">Vehicle Lease <input class="star-button" type="checkbox" /></a>
</div>
</li>
<li class="nav-item dropdown"> <a
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"> Quote & Order </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Quote Requests <input class="star-button" type="checkbox" /></a>
<a class="dropdown-item" href="#">Quotes for Review <input class="star-button" type="checkbox" /></a>
<a class="dropdown-item" href="#">Vehicles Orders <input class="star-button" type="checkbox" /></a>
<a class="dropdown-item" href="#">Release Quotes <input class="star-button" type="checkbox" checked/></a>
</div>
</li>
</ul>
</div>
<nav>
<div class="overlay"></div>
I've been struggling for a few days to enable users to toggle multiple drop downs open at the same time. While I did manage to get them to open simultaneously at one point, they then became unresponsive and couldn't be closed. Any help would be greatly appreciated.