Skip to content

lib/web/mage/dropdowns.js fails when autoclose is set to true #15469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brian-labelle opened this issue May 23, 2018 · 3 comments
Closed

lib/web/mage/dropdowns.js fails when autoclose is set to true #15469

brian-labelle opened this issue May 23, 2018 · 3 comments
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: PR Created Indicates that Pull Request has been created to fix issue

Comments

@brian-labelle
Copy link
Contributor

Magento's lib/web/mage/dropdowns.js has a bug that prevents a developer from specifying autoclose: false as an option for the dropdown function.

Preconditions

  1. Magento 2.2 or greater
  2. Any version of PHP, MySQL
  3. Any Browser

Steps to reproduce

  1. Call function 'dropdown' on a jquery element, specifying 'autoclose: false' as an option
$(this.selector).dropdown({
    autoclose: false
});
  1. Open the dropdown
  2. Click anywhere inside the dropdown content

Expected result

  1. The dropdown should remain open

Actual result

  1. Console error indicating we cannot call function hasClass on undefined
    1. el is undefined
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label May 23, 2018
@brian-labelle
Copy link
Contributor Author

brian-labelle commented May 23, 2018

See lines 129-143 of lib/web/mage/dropdowns.js

elem.on('click.toggleDropdown', function () {
	var el;

	if (options.autoclose === true) {
		el = actionElem;

		actionElem = $();
		$(document).trigger('click.hideDropdown');
		actionElem = el;
	}

	self[el.hasClass(options.activeClass) ? 'closeDropdown' : 'openDropdown'](elem);

	return false;
});

el is only initialized as actionElem, which should be $(this), (the element we are calling dropdown on), when options.autoclose is true

As a result, if options.autoclose is false, el is undefined, so we cannot call function hasClass on it

@brian-labelle brian-labelle changed the title lib/web/mage/dropdowns.js fails when autoclose is set to lib/web/mage/dropdowns.js fails when autoclose is set to true May 23, 2018
@osrecio osrecio added the Progress: PR Created Indicates that Pull Request has been created to fix issue label May 25, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label May 27, 2018
@magento-engcom-team
Copy link
Contributor

Hi @brian-labelle. Thank you for your report.
The issue has been fixed in #15499 by @brian-labelle in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

@magento-engcom-team
Copy link
Contributor

Hi @brian-labelle. Thank you for your report.
The issue has been fixed in #15607 by @dmytro-ch in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: PR Created Indicates that Pull Request has been created to fix issue
Projects
None yet
Development

No branches or pull requests

3 participants