Menu won't close when anchor link is clicked (onepage menu navigation)

Created on 16 September 2020, over 4 years ago
Updated 28 May 2025, 12 days ago

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.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇫🇷France Dom.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024