Make WordPress Core

Opened 20 months ago

Last modified 20 months ago

#57308 new defect (bug)

Nav menu on Mobile remains open after clicking on an anchor link

Reported by: nickpagz's profile nickpagz Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords: needs-testing has-testing-info reporter-feedback
Focuses: Cc:

Description

Running WordPress version 6.1

Steps to reproduce:

  • Install WordPress, use the default Twenty twenty-three or Twenty twenty-two theme
  • Create a page, add some ipsum lorem to give length to the page, add a link to an element at the bottom of the page (#news for example), set this page as the home page from Reading settings
  • Create a menu item that links to your element on the page (#news in this example)
  • View the page on your mobile device
  • Click/tap the mobile menu icon to open the menu overlay
  • Click/tap on the #news link

Expected behaviour: the menu overlay closes and the page scrolls to the relevant element (the one with the #news anchor)

What happens instead: The menu overlay does not close when you click the link, obscuring the page content. Menu needs to be closed manually to view page content.

Change History (3)

#1 @costdev
20 months ago

  • Keywords needs-testing has-testing-info reporter-feedback added

Hi @nickpagz, welcome to Trac and thanks for the detailed testing instructions!

I tried this in the browser (using DevTools and mobile user agent), but couldn't reproduce it.

What mobile device and browser are you using, so that reproduction tests can include these?

Last edited 20 months ago by costdev (previous) (diff)

#2 @nickpagz
20 months ago

Hmm, this was on an iPhone 12 Mini using Chrome, all latest versions.
On Chrome desktop using mobile user agent (again iPhone), I can replicate but with the added bonus of the page scrolling back to the top when the menu is closed - though that could be the particular site I tested for this case. Let me do some additional testing and report back.

#3 @nickpagz
20 months ago

@costdev I've been able to narrow down the issue to the format of the link used.

If you simply use #news as your link, then all works fine. However, the link doesn't work if you're on a different page. Clicking it reloads the same page as the link is relative to the current page. So this really only works for single-page sites.

Using /#news will get you back to the homepage and the correct anchor. However, clicking on the link from the homepage causes the menu overlay to remain open.

Using an absolute url will work if you omit https:// (since it defaults to http) or use http://. Http works presumably because of the redirect to https, which causes a page reload which closes the menu overlay.

I'm not sure of the implications of having the links set to http from an SEO perspective, but a redirect and page reload seems less than ideal if you're already on the page. It seems like the best approach at the moment is an absolute url with an http protocol or omitting the protocol altogether is the only solution that works, as far as I can tell.

UPDATE: A downside to using the redirect approach is the redirect will be cached as a 301. So when a site visitor selects a subsequent anchor link from the menu the page gets reloaded to the first anchor link selected. Safari cache expiry is 300s, haven't checked on FF or Chrome, but the issue is present on both.

UPDATE 2: Looks like this might have actually been fixed in this GB PR .

Last edited 20 months ago by nickpagz (previous) (diff)
Note: See TracTickets for help on using tickets.