Start a new discussion

To start a new discussion please visit the discussions section of the GitHub home page of the project.

Discussions on GitHub

You can also search our old self-hosted forums for any useful information below but please note that posting new content here is not possible any more.

Reply To: Show current submenu in mobile view (itemActivate)

Home Forums Latest release 1.1.x + Bootstrap 4 addon Show current submenu in mobile view (itemActivate) Reply To: Show current submenu in mobile view (itemActivate)

#3777
admin
Keymaster

Hi, sorry for the delay! You’d need to use this option data-sm-options="{ markCurrentItem: true }" – this will make sure the script adds the “current” class automatically to the <a> element linking to the current URL.

And then include some additional JS at the end of you pages – something like this:

// SmartMenus jQuery + Bootstrap 4 - expand active sub menu on mobile toggle button click
$('.navbar-toggler').click(function() {
  var $nav = $('.navbar-nav');
  if (!$(this).is('[aria-expanded="true"]')) {
    // use the timeout to make sure it works after the navbar is expanded by the BS JS
    setTimeout(function() {
      $nav.smartmenus('itemActivate', $nav.find('a.current').eq(-1));
    }, 1);
  } else {
    $nav.smartmenus('menuHideAll');
  }
});

(You may need to change the selectors if you have multiple .navbar-toggler/.navbar-nav elements on your pages.)