First bug is that I was trying to post a bug report on Report a Bug but nothing happens when I press Submit. Second bug is here:
Hi Bootstrap Studio Team,
I hope this message finds you well. I would like to report an issue I encountered with the Greyscale template provided by Bootstrap Studio. The problem occurs when using a dropdown menu within the navbar. When the navbar is in the collapsed state (burger menu), clicking on a dropdown link causes the entire navbar to collapse.
After investigating, I identified the cause to be the attached JavaScript code that automatically collapses the navbar when any link is clicked. This behavior also affects dropdown links, which should be excluded from this functionality.
Here is the problematic JavaScript code from the template:
(function() {
âuse strictâ; // Start of use strict
var mainNav = document.querySelector(â#mainNavâ);
if (mainNav) {
var navbarCollapse = mainNav.querySelector('.navbar-collapse');
if (navbarCollapse) {
var collapse = new bootstrap.Collapse(navbarCollapse, {
toggle: false
});
var navbarItems = navbarCollapse.querySelectorAll('a');
// Closes responsive menu when a scroll trigger link is clicked
for (var item of navbarItems) {
item.addEventListener('click', function (event) {
collapse.hide();
});
}
}
// Collapse Navbar
var collapseNavbar = function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
if (scrollTop > 100) {
mainNav.classList.add("navbar-shrink");
} else {
mainNav.classList.remove("navbar-shrink");
}
};
// Collapse now if page is not at top
collapseNavbar();
// Collapse the navbar when page is scrolled
document.addEventListener("scroll", collapseNavbar);
}
})(); // End of use strict
The issue can be resolved by modifying the event listener to exclude dropdown links from triggering the collapse. Here is the modified code:
(function() {
âuse strictâ; // Start of use strict
var mainNav = document.querySelector(â#mainNavâ);
if (mainNav) {
var navbarCollapse = mainNav.querySelector('.navbar-collapse');
if (navbarCollapse) {
var collapse = new bootstrap.Collapse(navbarCollapse, {
toggle: false
});
var navbarItems = navbarCollapse.querySelectorAll('a');
// Closes responsive menu when a scroll trigger link is clicked
for (var item of navbarItems) {
item.addEventListener('click', function (event) {
// Check if the clicked link is a dropdown toggle
if (!event.target.classList.contains('dropdown-toggle')) {
collapse.hide();
}
});
}
}
// Collapse Navbar
var collapseNavbar = function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement or document.body.parentNode or document.body).scrollTop;
if (scrollTop > 100) {
mainNav.classList.add("navbar-shrink");
} else {
mainNav.classList.remove("navbar-shrink");
}
};
// Collapse now if page is not at top
collapseNavbar();
// Collapse the navbar when page is scrolled
document.addEventListener("scroll", collapseNavbar);
}
})(); // End of use strict
I hope this helps in addressing the issue. Thank you for providing such a great tool, and I look forward to seeing this improvement in future updates.
Best regards,
Frits