Problem/Motivation
Bootstrap 5 has changed the syntax for some data toggle attributes, but the bootstrap-barrio templates (at least for the main menu) have not been updated accordingly. As a result, out of the box drop-down menus don't work because they simply don't have the correct data attribute.
Steps to reproduce
- Create a main menu with some sub-menus and put that menu in your site (use for top-levels of dropdowns)
- Verify that it is rendering using the menu--main.html.twig template from bootstrap barrio theme (use twig debug for that)
- Try to click on a top-level menu item that has a submenu and see nothing happen
Proposed resolution
Edit line 58 of menu--main.html.twig in the bootstrap barrio theme's templates/navigation folder, and change "data-toggle" to "data-bs-toggle".
Comments
Comment #2
teknocat commentedComment #4
hatuhay commentedComment #5
hockey2112 commentedThis setting is already in place in 5.5.2, but the drop-down menu functionality is still broken. Is there an additional fix that needs to be applied?
Comment #6
hockey2112 commentedComment #7
twodThe default Bootstrap 5 version (5.0.0-beta1) is looking for the
data-bs-targetattribute on all the links to know which submenu to toggle, but it's not set. I changed my subtheme to use 5.0.2 and it works fine now.Comment #8
hockey2112 commentedI did the opposite... I changed "data-bs-toggle" to "data-toggle" and that fixed the issue. Why did this fix the problem?
Comment #9
esch commentedI was having the same issue and went through and made the proper HTML/CSS changes, however it was still broken. I then noticed that the theme was loading both CDN javascript libraries. The bundle and un-bundle versions. I commented out the un-bundled version and everything started working.
Comment #10
hatuhay commentedFor bootstrap 5.0 the attribute is
data-bs-toggle, according to Bootstrap Docs.Comment #11
hockey2112 commentedThis still only works for me when I change data-bs-toggle to "data-toggle". Why is this happening?
Comment #12
Syntapse commentedspent hours messing around with this without success.... quick dirty workaround without changing data attributes. add it to your own subtheme just in case this is not fixed in subsequent releases.
Comment #13
crutch commentedBarrio is great and I very much appreciate this theme but his has been an issue for us for the past 6 months since starting with Drupal 9 and Barrio for #block-mainnavigation.
The update to 5.5 again broke the small screen main nav dropdown menu. It has the same issue as before, small screen main menu drops down but won't collapse. We fixed by setting Barrio (base theme) to use no library, and Barrio Subtheme to load local library. Then changed subtheme.libraries.yml to reference a local bootstrap as shown below.
Okay, things worked fine here with the main nav opening and collapsing.
---
After a few composer updates recently, we are now Barrio 5.5 and the issue reappears. Nav bar opens but not closes on small screens. How can this be? I thought this was fixed by not depending on external library, ah!
---
Now we changed setting to load local library for Barrio (base theme) as well as keeping the setting to load local library on Barrio Subtheme. Then commented out boostrap_cdn references in subtheme.libraries.yml as shown below.
All seems to be working normally again now. data-bs-toggle data-bs-target weren't changed
Comment #14
crutch commentedCommenting out causes "AssertionError: CSS files should be specified as key/value pairs, where the values are configuration options." on D9.3.4 and php8.1 so removed
Comment #15
chikeI still am having this issue with 5.5.14.
I added a main menu item and added dropdown links to it. Hovering on the parent menu item shows the link but attempting to click on it does nothing. The child menu links are working.