title: mmenu Sidebar-Plugin not working properly (initial state closed)
body: <p>Im using the jquery mmenu plugin with the sidebar addon (<a href="https://mmenujs.com/docs/addons/sidebar.html" rel="nofollow noreferrer">https://mmenujs.com/docs/addons/sidebar.html</a>). Unfortunately I'm having trouble getting the intital state to work properly.</p>
  <pre><code>const menu = new Mmenu(
      &quot;#menu&quot;,
      {
          counters: {
              add: true,
          },
          iconPanels: {
              add: true,
              visible: &quot;first&quot;,
          },
          navbar: {
              title: &quot;...&quot;,
          },
          navbars: [
              {
                  position: &quot;top&quot;,
                  content: [&quot;searchfield&quot;],
              },
              {
                  position: &quot;top&quot;,
              },
          ],
          setSelected: {
              hover: true,
              parent: true,
          },
          sidebar: {
              collapsed: {
                  use: 768,
              },
              expanded: {
                  use: 1440,
                  initial: &quot;closed&quot;,
              },
          },
          theme: &quot;white&quot;,
      },
      {
          offCanvas: {
              page: {
                  selector: &quot;#page&quot;,
              },
          },
          searchfield: {
              cancel: true,
              clear: true,
          },
      }
  );
  </code></pre>
  <p>Problem: If I open the html file for the first time (viewport &gt; 1440px), the menu is closed (cool!). But if I switch to another tab in my browser or minimize the window and reenter, the menu opens. Seems to be related with the event &quot;visibilitychange&quot;. You can test it, if you download the mmenu master (<a href="https://github.com/FrDH/mmenu-js/archive/master.zip" rel="nofollow noreferrer">https://github.com/FrDH/mmenu-js/archive/master.zip</a>) with the demos and open the advanced.html</p>
  <p>As a little fix I can close the menu with the visibilitychange event, but if the user opens the menu, changes the tab and then go back, I don't want the menu to close!</p>
  <pre><code>const api = menu.API;
  document.addEventListener(&quot;visibilitychange&quot;, function() {
    setTimeout(function() { api.close(); }, 50);
  });
  </code></pre>
  <p>Any ideas?</p>