Magento 2 – Make Mobile Menu Appear Sooner

magento2

The mobile menu appears at 768px and I want to change that to a custom value.

I've read on here to do the following:

The JS for the menu that has that functionality can be found in

lib/web/mage/menu.js

First create the folder structure in your theme ex:

[Namespace]/[theme_name]/web/mage/

And copy menu.js from lib/web/mage/menu.js to [Namespace]/[theme_name]/web/mage/menu.js

And change

 mediaBreakpoint: '(max-width: 768px)'

to

mediaBreakpoint: '(max-width: 1025px)'

But this isn't working, can anyone help please?

Best Answer

Override

/vendor/magento/theme-frontend-blank/web/js/navigation-menu.js

in your theme

/app/design/frontend/Vendor/YourTheme/web/js/navigation-menu.js

Change in line No. 400

media: '(min-width: 768px)', 

TO

media: '(min-width: 1024px)',

Override

/vendor/magento/theme-frontend-blank/web/css/source/_navigation.less

in your theme

/app/design/frontend/Vendor/YourTheme/web/css/source/_navigation.less

Change in line No. 51

.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {

TO

& when (@media-target = 'mobile'), (@media-target = 'all') {
@media all and (max-width: (@screen__l)) {
    // Your code here
}
}

Change in line No. 275

.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {

TO

& when (@media-target = 'desktop'), (@media-target = 'all') {
@media all and (min-width: (@screen__l)) {
    // Your code here
}
}
Related Topic