Problem/Motivation

When configuring a onepage website with sections discriminated by IDs, you will have a main menu which item links are of type:
<front>#anchor
In this case, a click on the menu will navigate on the same page, thus not trigger a page refresh. Doing so, the superfish menu won't close. In mobile navigation, that feels odd because user does not notice he actually moved to the desired link.

Steps to reproduce

  1. Install a fresh Drupal 8
  2. Install and activate the superfish menu and it's library
  3. Configure le main menu for instance to actually use superfish
  4. Add in your menu multiple links (eventually hierarchically to test also submenus) with links like <front>#anchor. That wil give you a onepage website, with the menu linking to your content sections
  5. Use the superfish menu as a user would, including in smallscreen : you will navigate to your various page section, but the menu won't close as you do.

Proposed resolution

Add a 'click' listener on menu items to actually close the menu if items are not submenu open/close placeholders (what is called 'button' is code)

Remaining tasks

Because the code actually belong here: https://github.com/mehrpadin/Superfish-for-Drupal
I made a pull request there. But the issue is opened here to let users find it more easily.

API changes

No API change breaks
But it will probably add a function to close the menu, I wonder if exposing publicly that function would also let users that want to close the superfish when click anywhere on page could use it.

Comments

Dom. created an issue. See original summary.

dom.’s picture

Issue summary: View changes
Status: Active » Needs work

Pull request as been created for this: https://github.com/mehrpadin/Superfish-for-Drupal/pull/30

dimitri1972’s picture

The new code to fix this problem works fine for me. Thx

adnaj_bukaj’s picture

#2 did not work for me.
Ended up with simple custom script loaded with theme.
When user clicks on link, class "sf-expanded" is removed and class "sf-hidden" is added.
Hope this will help someone. I´m ready to hear better solution!
_________________________________________________________

    jQuery(document).ready(function($) {
        $('#superfish-main-accordion a').on('click', function() {
            $('#superfish-main-accordion').removeClass('sf-expanded');
            setTimeout(function() {
                $('#superfish-main-accordion').addClass('sf-hidden');
            }, 630);
        })
    });

_________________________________________________________

  • lobsterr committed 3c37a046 on 8.x-1.x
    Issue #3171215 by dimitri1972, adnaj_bukaj, lobsterr: Menu won't close...
lobsterr’s picture

Status: Needs work » Fixed

I found other way to handle it. it is available in a new release of library https://github.com/LOBsTerr/drupal-superfish/releases/tag/2.3.10

Thank you for your contribution

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.