Clicking Navigation links on the current page should close the mobile overlay.
What problem does this address?
The navigation block supports anchor/on-page links inside the overlay. When a user clicks these they navigate to the correct part of the page but the overlay doesn't close so it's not clear that has happened.
What is your proposed solution?
We should close the overlay when links inside it are clicked.
@annezazu This would be quite important in order to build a single page website. Without the whole concept breaks down on mobile.
I propose this is actually quite an important issue.
My recommendation to fix would be to use the Interactivity API and apply special handling to any "internal" links (those containing only #someanchor as the url value).
Some of this is here
https://github.com/WordPress/gutenberg/blob/b7d989e0dafb23866f65295a851e6b8734c3b693/packages/block-library/src/navigation/index.php#L498
But we might want to add to the core/navigation-link block itself:
https://github.com/WordPress/gutenberg/blob/b7d989e0dafb23866f65295a851e6b8734c3b693/packages/block-library/src/navigation-link/index.php#L1
I wasn't able to reproduce this issue. Below are my environment details:
- WordPress Version: 6.9-alpha-60275
- Gutenberg Version: 21.1.0
- Theme: TT5 1.2
- OS: macOS
- Browser: Chrome 137.0.0
https://github.com/user-attachments/assets/01de2790-d915-41f3-8987-7c710a3744d4
@scruffian It seems like the overlay does close whenever selecting any in-page/anchor link in the navigation block. I assume the bug might have been patched as of the latest version.
Please let me know if you are still able to reproduce it and if so, it would be great if you can share your environment info. Moreover, please let me know if I misunderstood it and was testing it wrong.
I can still replicate. Note that an "in-page/anchor" link has only #anchor in the URL, not any other content.
WordPress Version: 6.9-alpha-60093-src Gutenberg Version: 21.3.0 Theme: TT5 1.2 OS: macOS Browser: Chrome 137.0.7151.104
I’m still not able to replicate the issue 🤔 Here are my updated environment details:
WordPress Version: 6.9-alpha-60634 Gutenberg Version: 21.4.0 Theme: TT5 1.3 OS: macOS Browser: Chrome 138.0.0.0
I’ll write out the testing steps I used to ensure they align with your process:
-
Created a new page and added content to it to enable scrolling.
-
Added an HTML anchor to a heading element (block settings -> advanced -> HTML anchor).
-
Edited the navigation block and added a custom link with only
#secondas the link (matching the anchor I set in step 2). -
Tested on the frontend and the navigation overlay closed as expected when clicking the in-page link.
https://github.com/user-attachments/assets/2d593f7b-0bdd-437b-871d-8dcaac728ab7
@scruffian Please let me know if I’ve missed anything or misunderstood your comment.
I figured it out - when there's an element with the name on the page, the overlay does close, but if the element is missing, it doesn't. I'm not sure what we should do in that case...
I figured it out - when there's an element with the name on the page, the overlay does close, but if the element is missing, it doesn't. I'm not sure what we should do in that case...
I think we should still close, or do nothing. It's the simplest way to solve this issue when in this case a user error is involved.
If we want to go above and beyond, we can link to a search string: test.html#:~:text=your%20search%20string for the now-missing anchor. But it seems hard for a link to know that an anchor is missing. In any case, this isn't worth writing complexity for, when it's ultimately markup error.
Closing as fixed, if someone wants to go above and beyond, PRs are welcome.