Navbar dropdown menus not closing at click


Topic: Navbar dropdown menus not closing at click

Emme asked a year ago

Actual behavior Clicking on navbar dropdown menus the menu don't collapse/close as expected. This happens on Windows 10 pro but the behavior seems normal on Mac OS 10.11 - 15.

I tested with Firefox 70.00.1 Build Official 64 bit and Chrome 78.0.3904.87 Build Official 64 bit.

Resources (screenshots, code snippets etc.) This in a screencast gif: https://giphy.com/gifs/L3WtMOUyXPrL1F4LD7

You can see the behavior directly on the documentation page: https://mdbootstrap.com/docs/jquery/navigation/navbar/ and in some elements in https://mdbootstrap.com/docs/jquery/components/dropdowns/.

See also: https://mdbootstrap.com/support/jquery/navbar-dropdown-menus-not-closing/ (reporting similar problem).


Workaround:

$(document).ready(function() {
  $('body').on('mouseup', function (e) {
    if (!$(e.target).hasClass("dropdown-menu")) {
      $(".dropdown-menu").each(function () {
        $(this).removeClass("show");
      });
    }
  });
});

Emme commented a year ago

Many thanks Gianluca.


Please insert min. 20 characters.
Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: jQuery
  • MDB Version: 4.8.11
  • Device: Desktop
  • Browser: Firefox, Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes