Site logo

[Resolved] Disable Dropdown Menu Click on third level sub menus

Home Forums Support [Resolved] Disable Dropdown Menu Click on third level sub menus

Home Forums Support Disable Dropdown Menu Click on third level sub menus

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #1475411
    maxms

    Hello.

    I am using the navigation dropdown on click option. I have created a mega menu on one item which has two columns. In each column is one sub-item with it’s own sub-menu. So, the parent sub-items are also taking on the click option and I don’t want this. They need to go to their own urls.

    Is there a way to append or override the dropdown-click script to only work on the very top level of the main navigation?

    Thank you!

    P.S. This seemed to work correctly before updating to 3.0.

    #1475554
    Elvin
    Staff
    Customer Support

    Hi,

    P.S. This seemed to work correctly before updating to 3.0.

    Can you try purging site cache and see if it works correctly again?

    Let us know how it goes.

    #1477021
    maxms

    It’s close. The submenu arrow is gone and it doesn’t seem to be trying to toggle but the link on the parent (2nd level) isn’t working. The link shows when hovering but it goes nowhere.

    Thanks!

    #1477471
    Tom
    Lead Developer
    Lead Developer

    Strange, I don’t remember this functionality changing in 3.0.0.

    We could look at adding some custom javascript on your site that forces those links to go to their destination? If that sounds good, you would need to add a custom class to each of those two menu items that we can target with the JS.

    Then you could do this:

    <script>
        var customLinks = document.querySelectorAll( '.your-custom-class a' );
    
        for ( var i = 0; i < customLinks.length; i++ ) {
            customLinks[ i ].addEventListener( 'click', function() {
                var url = this.getAttribute( 'href' );
                window.location = url;
            } );
        }
    </script>

    Not 100% sure it’ll work, but should in theory 🙂

    #1477490
    maxms

    Howdy,

    Thanks so much for your response. I’ve added that script to a js file in my child theme and enqueued it. It seems to be loading correctly. I also added the custom class to those two menu items. However, the links still aren’t working. The sfHover class is still being added to those – does that make a difference? I feel like we should be removing the dropdown somehow as well.

    Thanks again,

    #1477752
    Tom
    Lead Developer
    Lead Developer

    Ah, forgot the forums strips [ i ] without the spaces. Try the updated code: https://generatepress.com/forums/topic/disable-dropdown-menu-click-on-third-level-sub-menus/#post-1477471

    #1478887
    maxms

    Hi Tom,

    The new code doesn’t seem to make a difference with those links. I can see the link when hovering over them and the <a> tag is there in the source code so I am not sure what is blocking the link action.

    Thanks so much for your time on this.

    #1479280
    Tom
    Lead Developer
    Lead Developer

    Let’s debug a little:

    var customLinks = document.querySelectorAll( '.your-custom-class a' );
    
    for ( var i = 0; i < customLinks.length; i++ ) {
        console.log(customLinks[ i ]);
        customLinks[ i ].addEventListener( 'click', function() {
            var url = this.getAttribute( 'href' );
            console.log(url);
            window.location = url;
        } );
    }

    Does anything show up in the console when the items are clicked?

    #1480943
    maxms

    No, nothing shows in the console on click with the new code.

    #1481091
    Tom
    Lead Developer
    Lead Developer
    #1485579
    maxms

    Still the same. No link and no console message. Sorry this is such a pain!

    #1485726
    Tom
    Lead Developer
    Lead Developer

    Weird – what about now?: https://generatepress.com/forums/topic/disable-dropdown-menu-click-on-third-level-sub-menus/#post-1479280

    Sorry for the debugging process – nothing is standing out as being broken quite yet.

    #1487294
    maxms

    OK, got the following error in console:

    Uncaught TypeError: Cannot read property ‘getAttribute’ of null
    at HTMLAnchorElement.t (dropdown-click.min.js?ver=3.0.1:1)
    t @ dropdown-click.min.js?ver=3.0.1:1

    Does that tell us anything?

    P.S. When I click on the error link it takes me to Line 1, Column 2224 in dropdown-click.min.js.

    #1487317
    Tom
    Lead Developer
    Lead Developer

    Hmm, not what I expected – nothing else in the console? Does that error go away if you undo the code we added?

    #1489191
    maxms

    Hi,

    No, and actually I can’t recreate that error with the added code either so I’m not sure what that was. Sorry!

    I’m not sure what to do here. I tried to rethink it but nothing else allows for the appearance that I need.

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.