question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[HELP] How to prevent menu closing from firing on sidebar links

See original GitHub issue

Is your feature request related to a problem? Please describe.

When I click on a sidebar item that is a link, the sidebar animation of closing the menu is fired, and the new page doesn’t load until after the animation, recreating an unnecessary delay.

Describe the solution you’d like

This is likely a configuration / HTML problem in my code, hoping someone can tell me what I’m doing wrong.

Additional context

For example, https://anki-subtitles.herokuapp.com/ – click on credits, and it opens a submenu. Clicking on either items closes the menu before opening the new page.

<li class="nav-item menu-open nav-item">
   <!-- collapsible ancestor-->
   <a class=" nav-link  active">
      <span class="nav-icon fas fa-circle"></span>
      <p>
         <!-- spanElement -->
         <span>Credits </span>
         <span class="end fas fa-angle-left"></span>
      </p>
   </a>
   <ul class="nav-treeview menu_level_1">
      <!-- has leaf_class -->                        
      <li class="f nav-link leaf">                            
         <a href="/credits/bundles">
         Bundles 
         </a>
      </li>
      <!-- has leaf_class -->                        
      <li class="active last nav-link leaf">                                        
         <a href="/credits/javascript" class=" active">
         Javascript 
         </a>
      </li>
   </ul>
</li>

The javascript I’m using is a copy of what’s generated from the gulp build command, and is included in my webpack config. It seems to work, except for this issue.

https://github.com/survos/BaseBundle/blob/master/src/Resources/assets/js/adminlte.js

Alas, my javascript skills are limited. I think the issue is that the close menu event is being fired on the entire tree, when really I just want it to fire on the -treeview items (the branches, not the leaves).

domReady(() => {
        const button = document.querySelectorAll(SELECTOR_DATA_TOGGLE$1);
        for (const btn of button) {
            btn.addEventListener('click', event => {
                // event.preventDefault()
                const treeviewMenu = event.target;
                const data = new Treeview(treeviewMenu, Default$1);
                data.toggle();
            });
        }
    });

Any suggestions?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
tacmancommented, Sep 17, 2021

THANKS!!! I’m embarrassed about how many hours I looked for that, and couldn’t see what was wrong.

Works as expected now.

0reactions
REJackcommented, Sep 16, 2021

your sidebar html markup isn’t correct, you set .nav-link to the li-tag but that need on the a-tag and you need to set .nav-item to the li-tag.

like this:

<li class="nav-item">
  <a href="./index.html" class="nav-link ">
    <i class="nav-icon far fa-circle"></i>
    <p>Dashboard v1</p>
  </a>
</li>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid dropdown menu close on click inside - Stack Overflow
First by handling the click on the link to open/close the dropdown like this ... and then listening the clicks outside of the...
Read more >
How to avoid dropdown menu to close menu items on clicking ...
How to avoid dropdown menu to close menu items on clicking inside ? · Click Inside: · Click Outside: O/P after click outside....
Read more >
Dropdowns · Bootstrap v5.1
Wrap the dropdown's toggle (your button or link) and the dropdown menu ... by 25% and remove the margin-left that's added for regular...
Read more >
Exploring the Sidebar and Game Menu in Fortnite Creative
Open the Game Menu by clicking the gear (Menu) icon above the red arrow (Exit) icon. Return to the Lobby or close Fortnite...
Read more >
Drilldown Menu | Foundation for Sites 6 Docs
Use a class name for independent styling; the JS applied class: `is-drilldown` is required. Remove the backslash (`\`) if copy and pasting. data-parent-link...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found