Skip to content

Fix mobile menu collapsing on scroll in iOS Safari#2261

Open
PeterKnightDigital wants to merge 1 commit into
letsencrypt:mainfrom
PeterKnightDigital:mobile-scroll-fix
Open

Fix mobile menu collapsing on scroll in iOS Safari#2261
PeterKnightDigital wants to merge 1 commit into
letsencrypt:mainfrom
PeterKnightDigital:mobile-scroll-fix

Conversation

@PeterKnightDigital

@PeterKnightDigital PeterKnightDigital commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What this fixes

On iPhone and iPad, opening the mobile navigation menu and then scrolling down causes the menu to snap closed before you can tap a link. This makes it impossible to navigate the site using the mobile menu on iOS Safari — a potentially significant issue given how much traffic comes from mobile devices.

Why it happens

iOS Safari fires a resize event whenever the user scrolls, because the browser address bar slides away as you scroll down (changing the visible height of the page). The menu's resize handler interpreted this as a layout change and hid the navigation menu — even if the user had just opened it intentionally.

The fix

A one-line guard checks whether the menu is currently open before hiding it. If the user has the menu open, the resize event from scrolling is ignored. The menu still closes correctly in all other cases (e.g. rotating the device, resizing a browser window on desktop).

Steps to reproduce (before fix)

  1. Open letsencrypt.org on iPhone in Safari
  2. Tap the hamburger menu (☰) to open navigation
  3. Tap About Us to expand the submenu
  4. Swipe up to scroll down the page
  5. Menu collapses — links become unreachable

Test plan

  • Reproduced the bug on iPhone Safari (confirmed above steps)
  • Verified fix on iPhone Safari: menu stays open when scrolling
  • Verified menu still closes correctly when rotating device (expected behaviour)

iOS Safari fires a resize event when scrolling because the browser
address bar hide/show changes window.innerHeight. The initResizeHandler
was unconditionally hiding the nav on every mobile resize, collapsing
a menu the user had intentionally opened.

Guard the classList.add('hidden') call so it only runs when the menu
is not currently expanded (aria-expanded !== 'true').

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant