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

fix scroll issues for textarea on divs with overflow #298

Conversation

mst-avaleo
Copy link

The commit fixes scroll issues with textarea which are on a div with overflow. autosize is changing scrollTop of the parent div during update after text height. In result textarea is jumping when using is typing something in the field. The problem is significant for bigger texts.

The commit fixes scroll issues with textarea which are on a div with overflow. autosize is changing scrollTop of the parent div during update after text height. In result textarea is jumping when using is typing something in the field. The problem is significant for bigger texts.
@jacksondc
Copy link

It seems the compiled js didn't get committed (dist/autosize.js and dist/autosize.min.js). Hoping a fix for this issue gets merged soon!

Michal Stochmialek added 2 commits July 13, 2016 09:09
@mst-avaleo
Copy link
Author

I've added missing dist files. The fix works in our application pretty well. I'm also hoping for quick merge of the fix, since then I could remove fork from our app.

@jacksondc
Copy link

Thanks! That's working great for nested textareas, but it looks like it breaks when there is no parent with overflow: auto ("Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'").

I think findOverflowParent might need to do something like this:

while(element.parentNode) {
  element = element.parentNode;
  if(element === document) { // there is no overflow parent
    return null;
  } else {
    var elementStyle = window.getComputedStyle(element, null);
    var overflowValue = elementStyle.getPropertyValue('overflow-y');
    if (overflowValue === 'auto') {
      return element;
    }
  }
}

@mst-avaleo
Copy link
Author

Ah, that's true. In our project we don't have this case. Here's a fix, similar to what you proposed.

@jacksondc
Copy link

I'm using the fork in my project too, now, and it's working great. Thanks @mst-avaleo!

@jackmoore jackmoore closed this in b7f7306 Jul 13, 2016
@jackmoore
Copy link
Owner

Thanks @mst-avaleo. My apologies for the late response to your pull request. I think you did a good job, but there was a couple of things I wanted to do a little different. I committed an alternative fix for this using your code as a guide, let me know how it works for you.

@jackmoore
Copy link
Owner

I worried about the performance impact of calling getComputedStyle on every ancestor node, so I replaced that with just a check for the scrollTop value, since that was what was actually needed. Since changing the height of the textarea element may impact the overflow of more than one parent element, I changed it to restore the overflow for all ancestor elements (which removed the need to specifically target document.body).

@mst-avaleo
Copy link
Author

It works like my fix, so I'll switch to official 3.0.16. Thanks for the final fix!

@jackmoore
Copy link
Owner

👍 Thank you

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.

None yet

3 participants