Close dropdown menu

This seems to do the trick.

this.$element.find(".w-dropdown-list a").click((function() {
  this.$element.find(".dropdown").triggerHandler("w-close.w-dropdown");
}

w-close.w-dropdown is closeEvent + namespace when inspecting the code.

It’s a bit dodgy, but it’s better than this:

  this.$element.find(".dropdown-toggle, .w-dropdown-list").removeClass("w--open");
  this.$element.find(".dropdown-toggle").attr("aria-expanded", "false");
  this.$element.find(".dropdown").css("z-index", "");
  $.data(this.$element.find(".dropdown")[0], ".wDropdown").open = false;

which is the first way I managed to avoid the two clicks needed to re-open

Edit: this.$element is just a reference to the top level element of the dropdown as a jQuery element. If you have more than one drop down on a page, this needs to run for each dropdown with the correct reference.

2 Likes