xobotyi/react-scrollbars-custom

Scrollbar gets stuck in bottom after scrollable content becomes shorter

andrewvarga opened this issue · 0 comments

Is your feature request related to a problem? Please describe.

Not sure if this is a bug report or a feature request, but I have a problem:

  • I have a vertically scrollable content
  • I go to the bottom of the scroll
  • then I remove some items from the content programatically so that the scrollable content is now smaller in height than the visible area (clientHeight) so there is nowhere to scroll to.

After this the scroll position is still at the bottom even though there is no content there, and so when I start scrolling up, the scrollbar gets smaller and eventually disappears.

Describe the solution you'd like

It would be good if this was caught automatically and the scrollbar would disappear if the content to be scroller becomes smaller.

Describe alternatives you've considered
I could detect if that happens in onUpdate but it feels like a hack:

let scrollTop = rect.scrollTop;
const extraThresholdToAvoidFlickering = 5;
const hasScrolledIntoEmptyBottomArea = rect.scrollHeight - extraThresholdToAvoidFlickering > rect.contentScrollHeight;
if (hasScrolledIntoEmptyBottomArea) {
   scrollTop = 0;
}