FIX: prevent auto-scroll when setting focus inside header panels (PR #14822)


When one of the header panels is opened, there’s some logic to set the focus either on the first link - in the case of the hamburger and user menus - or the search bar in the case of the search panel.


User menu

Search panel

When focus() is called, the browser automatically scrolls to that element. This wouldn’t normally be an issue; however, since the header is set to sticky, it causes problems on Chrome specifically. Here’s what it looks like

and it’s even more prominent on topic pages since it tries to find the top of the page, causing more posts to load, which causes the height to change, which causes jitter.

This PR adds the preventScroll option to focus() to prevent this automatic scrolling

Here’s what it looks like after


This is quite interesting, thank you.

This pull request has been mentioned on Discourse Meta. There might be relevant details there: