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:
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
- 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:
- Created 4 years ago
- Reactions:4
- Comments:11 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@caitecoll It could be a timing issue with the autofocus behavior of iOS. Did you try to replace it with a React.useEffect?
@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).