-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Description
Steps to reproduce
- Initialize a new mage.menu in a .phtml
<ul data-mage-init='{"menu":{"responsive":false, "expanded":true, "delay":0, "position":{"my":"left top","at":"left bottom"}}}'>
(I wanted to split mobile and desktop navigation into 2 templates) - View website in < 768px browser
- Open and close default mobile menu.
Problem
Menu will close, but opens again right after.
Possible cause
This seems to be due to setting the same onClick event multiple times on $('[data-action="toggle-nav"]') and $('.nav-sections') (in lib/web/mage/menu.js) when initializing the widget.
Quick fix
Change
toggle: function () {
if ($('html').hasClass('nav-open')) {
$('html').removeClass('nav-open');
setTimeout(function () {
$('html').removeClass('nav-before-open');
}, 300);
} else {
$('html').addClass('nav-before-open');
setTimeout(function () {
$('html').addClass('nav-open');
}, 42);
}
},
to
toggle: function () {
if ($('html').hasClass('nav-open')) {
$('html').removeClass('nav-open');
setTimeout(function () {
$('html').removeClass('nav-before-open');
}, 300);
} else if(!$('html').hasClass('nav-before-open')) {
$('html').addClass('nav-before-open');
setTimeout(function () {
$('html').addClass('nav-open');
}, 42);
}
},
casiandaniel