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

prevent stuck left-scroll due to negative value #56

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

Andrwe
Copy link
Contributor

@Andrwe Andrwe commented Mar 12, 2025

Currently scroll(event, "left") only works when the calculated scroll value (left) is higher than zero. When the scroll area is small (e.g. only 4 items) then the calculated scroll value is always below zero. Still this value can be used for inner.scroll() as a negative value also indicates scrolling into left direction.
This issue can be seen on https://hbstack.dev/modules/components/slide/ when scrolling to right direction only once and then trying to scroll left. It fails as it always ends up in
https://github.com/Andrwe/hbstack-slide/blob/main/assets/hb/modules/slide/js/index.ts#L20

This patch changes the calculation of scroll value by using the maximum out of either inner.scrollLeft - step or 0 - inner.scrollLeft. This results in left scrolling by either a value that is smaller than the left scrolling area or scrolling to 0 and therefore showing the left-most item.
Because of this change the check for out-of-bound scrolling based on L20 can be removed as the calculated value is always within the bounds of the scrolling area.

Verified

This commit was signed with the committer’s verified signature.
bagxi Yauheni Kachan
Currently `scroll(event, "left")` only works when the calculated scroll
value is higher than zero. When the scroll area is small (e.g. only 4
items) then the calculated scroll value is always below zero. Still this
value can be used for `inner.scroll()` as a negative value also indicates
scrolling into left direction.
This issue can be seen on https://hbstack.dev/modules/components/slide/
when scrolling to right direction only once and then trying to scroll
left. It fails as always ends up in
https://github.com/Andrwe/hbstack-slide/blob/main/assets/hb/modules/slide/js/index.ts#L20

This patch changes the calculation of scroll value by using the maximum
out of either `inner.scrollLeft - step` or `0 - inner.scrollLeft`.
This results in left scrolling by either a value that is smaller than
the scrolling area or scrolling to 0 and therefore showing the left-most
item.
Because of this change the check for out-of-bound scrolling based on L20
can be removed as the calculated value is always within the bounds of
the scrolling area.

Signed-off-by: Andrwe Lord Weber <github@andrwe.org>
@razonyang razonyang merged commit e5264f1 into hbstack:main Mar 13, 2025
1 check passed
@razonyang
Copy link
Member

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

2 participants