Mobile Nav

@sgroup/mobile-nav

The mobile nav component is a vanilla JS component that aims to do a single thing - toggle a class on the <html> element, to let other components on the page control how the mobile menu should be shown. It's this hands-off approach that allows each project to use this component, withough being opinionated at all.

Despite it being a glorified "class-toggler" - there are some handy utilities specifically for mobile menus.

Usage

Import the @sgroup/mobile-nav module, and call its constructor.

import MobileNav from '@sgroup/mobile-nav';

new MobileNav({
    // ....
});

Available options

OptionTypeDefaultDescription
openSelectorString[data-mobile-nav-open]The selector string for all open triggers (supports multiple)
closeSelectorString[data-mobile-nav-close]The selector string for all close triggers (supports multiple)
activeClassStringmobile-nav-openThe class to toggle on the <html> element when clicked.
classElementHTMLElementdocument.documentElementThe element the active class should be applied to.
enableScrollLockBooleantrueWhether to lock scrolling when triggered.
scrollLockElementHTMLElementdocument.bodyThe element scroll-locking should apply to.
scrollLockOptionsObject{ reserveScrollBarGap: true }Settings for the body-scroll-lock package.

Examples

Mobile menu example