MurhafSousli / ngx-scrollbar

Custom overlay-scrollbars with native scrolling mechanism
https://ngx-scrollbar.netlify.app/
MIT License
618 stars 99 forks source link

Issue with ngx-scrollbar and Autosize Textarea #617

Closed JayAhn2 closed 4 months ago

JayAhn2 commented 4 months ago

Reproduction

Use StackBlitz to reproduce the issue: https://stackblitz.com/edit/6x7kqx

  1. Open this StackBlitz project.

  2. Write a long text into the textarea that exceeds 300px in height, causing the vertical scrollbar in the ng-scrollbar tag to appear.

  3. Scroll to the middle of the text and try to type something in the middle of the textarea.

Move to scroll to the middle

image

Type somthing

image

Expected Behavior

When typing in the middle of the textarea, the vertical scrollbar should remain in its current position unless the text cursor (caret) is moved out of the visible area.

Actual Behavior

When typing in the middle of the textarea, the vertical scrollbar automatically moves to the top, causing the text view to jump unexpectedly. This behavior disrupts the user experience as the scrollbar should not move as long as the text cursor is within the visible area.

Environment

MurhafSousli commented 4 months ago

The actual behavior is the native expected behavior, try removing the scrollbar and use overflow: auto on a div instead, you will get the same behavior.

JayAhn2 commented 4 months ago

You are right. It happens not only with ngx-scrollbar but also with overflow: auto.

I think it is not quite desirable behavior as normally scrollbar isn't moved to anywhere as far as text cursor is positioned within the scrolled view...

If you don't mind, do you have any idea to avoid this issue?

Many thanks!

JayAhn2 commented 4 months ago

@MurhafSousli Seems I found the bug issue related to cdkTextareaAutosize

https://github.com/angular/components/issues/23834

Thanks!