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

Scroll position doesn't stay at the bottom when viewport height changes #301

Open
mariia-mitiureva opened this issue Dec 28, 2023 · 10 comments

Comments

@mariia-mitiureva
Copy link
Contributor

Describe the bug

If scroll reaches the very bottom position, it stays at the bottom when items are resized. It actually works and looks like expected behavior to me.
However, when viewport size changes, it doesn't work like this (see attached video)
https://github.com/inokawa/virtua/assets/37265338/dcd04cd9-4682-4d12-af6d-3e9dd75f185e

To Reproduce

  1. Open Storybook -> Advanced -> Chat
  2. Comment out new messages generation
  3. Change browser window height

Expected behavior
I think, scroll position should stay at the bottom on any size changes

Platform:

  • Browser: I checked it in Chrome and Safari
  • Version of this package: 0.18.0
  • Version of framework: react 18.2.0
@inokawa
Copy link
Owner

inokawa commented Dec 28, 2023

Hi, this behavior is currently expected one. What do you need it for?

@mariia-mitiureva
Copy link
Contributor Author

mariia-mitiureva commented Dec 28, 2023

I use it for a chat app. It seemed logical to me, that scroll position stays at the bottom. When a user opens a chat and then resizes the window, I would be weird not to see the very beginning of the conversation.

Do you think this behavior might be wrong in some cases? Could it stay at the bottom for reverse: true only?

@inokawa
Copy link
Owner

inokawa commented Dec 28, 2023

Thanks. It seems worth implementing.
I think it should be for reverse: true because it is different from native behavior of scrollable element and it is required only for chat like reverse scrolling usage.

@inokawa inokawa self-assigned this Jan 11, 2024
@mariia-mitiureva
Copy link
Contributor Author

Hi @inokawa! Do you have any estimates for this issue?

@inokawa
Copy link
Owner

inokawa commented Jan 16, 2024

It's planned but not right away.

@LookRain
Copy link

hi @inokawa do you a rough idea on how you would implement it? I would like to help with this feature

@inokawa
Copy link
Owner

inokawa commented Apr 18, 2024

This library doesn't know the current distance to the bottom end. It's necessary restriction to support #315.

So I would add onResize like prop and allow users to implement their own "scroll to bottom if at bottom" logic if I try to do.

if (
ref.current.scrollOffset -
ref.current.scrollSize +
ref.current.viewportSize >=
// FIXME: The sum may not be 0 because of sub-pixel value when browser's window.devicePixelRatio has decimal value
-1.5
) {
setIsAtBottom(true);

@mariia-mitiureva
Copy link
Contributor Author

@inokawa so this means that users need to have an ability to scroll to bottom synchronously. Now it's not possible

@mariia-mitiureva
Copy link
Contributor Author

@inokawa hi, does what you said above apply to #408 as well? I mean "This library doesn't know the current distance to the bottom end. It's necessary restriction to support #315."

And do you have any idea how to allow users to scroll to bottom synchronously?

@inokawa
Copy link
Owner

inokawa commented Aug 2, 2024

Both may need onResize like prop but not sure.

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