question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autofocus input inside popper content causes scroll jump

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

Opening a Popper with an autofocus input inside it, should not cause the page to jump (scroll).

Current Behavior 😯

It causes a scroll jump.

Reason

That happens because at the moment the popper element is appended to body, the styles are not applied yet (in the first render of the popper). Then react-dom detects an autofocus input is added to the dom and calls .focus() on it:

image

Then the browser behavior is to scroll the focused element into the view, which cases a jump.

Steps to Reproduce 🕹

Link: https://codesandbox.io/s/material-demo-clitd

  1. click on the “Toggle Pupper” button.

Context 🔦

Not so important IMO.

Your Environment 🌎

Tech Version
Material-UI v4.2.1
React 16.8
Browser Chrome
TypeScript yes
etc.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jan 29, 2021

@caitecoll It could be a timing issue with the autofocus behavior of iOS. Did you try to replace it with a React.useEffect?

0reactions
caitecollcommented, Feb 1, 2021

@oliviertassinari Yes, thanks, that’s the workaround we used. Just to be clear, the issue is present in Safari desktop (haven’t tested on mobile).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autofocus input inside popper content causes scroll jump
Opening a Popper with an autofocus input inside it, should not cause the page to jump (scroll). Current Behavior. It causes a scroll...
Read more >
Prevent auto focus of a material-ui popover element
The pop-up always gets focussed. I have tried programmatically setting the focus using refs but I cannot give a stateless function component (I' ......
Read more >
[Solved]-Material ui select move the scroll to top if all items are ...
This issue is that material-ui's autoFocus goes to the last item by default. I couldn't get it to work differently unfornately (it seems...
Read more >
sitemap.xml - Material Design for Bootstrap
... https://mdbootstrap.com/support/general/content-animation-not-working-in- ... .com/support/general/modal-with-long-content-causes-background-to-scroll/ ...
Read more >
Release Notes - HackMD
Fix unexpected scrolling behavior in edit page; Fix a bug of resetting password in dashboard; Fix book mode might showing wrong page on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found