Drupal Bootstrap 3 multilevel submenus with hover


PROBLEM

We all love Bootstrap framework for so many reasons but, there are quite a few of us who hate its default menu behaviour mainly because it's optimised for touch, with little consideration for desktop devices. My view is that both should be given equal consideration because we're simply not that far along in the future to ignore desktop devices. Judging by developer responses in Bootstrap issue queue this is not about to change and we will most likely never see its menus behaving like they do in Zurb Foundation framework for example.

There has been a lot of discussion in Drupal 7 Bootstrap theme project issue queue relating to revealing submenu's on hover instead of click event which is the default Bootstrap behaviour. The other thing that bothered a lot of people including myself was «dead» parent menu items that wouldn't navigate to a page or node as is the default Drupal menu behaviour as well as, behaviour most people are used to and still expect it at least on desktop devices. Indeed I was the one to originally start the discussion and help find a workable solution in Bootstrap 7.x-2.x issue queue.

Then Bootstrap 3 was released with even more reasons to love it and an extra reason to hate its default menu behaviour — .dropdown-submenu support was removed. Predictably Drupal's Bootstrap theme project issue queue reactivated on the matter just as it did all over the web for non Drupal themes. We cannot nor should we expect Drupal Bootstrap theme project managers to tackle the issue as they are understandably so trying to stick with default Bootstrap behaviours, and they are volunteers after all. But there is a solution I found that I am happy to share, and it is surprisingly simple to implement.

THE SOLUTION

And that's all it takes. End result however, is amazing. Not only do you get your menus to behave the way most people still expect them to on desktops but, you also have them behaving great on mobile, touch devices as well.

Some of the key features quoted from author's website

  • Optimised for mobile and desktop browsers supporting touch, mouse or both inputs at the same time
  • Section 508 compliant and fully accessible to assistive technology like screen readers
  • Unlimited menu trees on the same page and unlimited sub menu levels supported
  • Horizontal or vertical main menu items arrangement
  • Absolute/relative/fixed positioning for the main menus supported
  • Right-to-left and bottom-to-top display of the sub menus is possible
  • Full support for RTL text/pages (e.g. Hebrew, Arabic)
  • Full window size detection — the menus will always be kept inside the window's boundaries
  • Automatically adjustable width for the sub menus is possible (including min/max settings)
  • Keyboard navigation friendly (Tab key)

If you're still not convinced checkout the demo and decide for yourself. As always, if you have a better solution or a question feel free to post a comment. And don't forget to share.

0 comments