Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page automatically scroll to top when focus in Chrome 61 #457

Open
froyog opened this issue Sep 20, 2017 · 5 comments
Open

Page automatically scroll to top when focus in Chrome 61 #457

froyog opened this issue Sep 20, 2017 · 5 comments

Comments

@froyog
Copy link

froyog commented Sep 20, 2017

When clicking the main part of the editor, the editor will focus (which is expected) but the whole page will automatically scroll to top. I did some digging to the source code and found out that when clicking, this method will be invoked

focusEditor: Function = (): void => {

and caused the page to scroll.

I tried to fix it with an ugly apporach which save the current location first and scroll to it after focus:

  focusEditor: Function = (): void => {
    setTimeout(() => {
      let x = window.scrollX;
      let y = window.scrollY;
      this.editor.focus();
      window.scrollTo(x, y);
    });
  };

This bug only seems to appear in Chorme 61.

@jpuri
Copy link
Owner

jpuri commented Sep 20, 2017

@scarlet608 : can you plz check if you face this issue here also: https://jpuri.github.io/react-draft-wysiwyg/#/ and here: https://draftjs.org/

@froyog
Copy link
Author

froyog commented Sep 22, 2017

@jpuri Nope. Sorry for the late reply. I double checked everything and it only appears in my project in Chrome 61.

The editor worked totally fine in Firefox, Edge and Safari and it even worked in Chrome 60 (before update) but failed in Chrome 61 and 63. I havn't chnaged a single line of my code. So it seems like a browser behavior.

As I mentioned before, this line caused the issue

this.editor.focus();

and everthing else works perfectly fine. I am really wondering what caused the problem.

@icd2k3
Copy link

icd2k3 commented Sep 27, 2017

I'm having the same issue with draft-js (autofocus) and Chrome 61 (works fine in Firefox), so looks like it may likely be a Chrome bug?

@jpuri
Copy link
Owner

jpuri commented Sep 28, 2017

That is weird, but yes can be chrome issue 😄

@froyog
Copy link
Author

froyog commented Oct 13, 2017

@icd2k3 @jpuri
I finally figured out a solution to this issue by creating a new project and paste all of my code into the new one (not changing a single line of the old code). I think it might be a issue with create-react-app or chrome but copy & pasting actually fixed my issue.

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

No branches or pull requests

3 participants