prevent stuck left-scroll due to negative value #56
+2
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 forinner.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
or0 - 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.