Skip to content

Commit

Permalink
fix: divisor cannot be 0 (#72)
Browse files Browse the repository at this point in the history
* Divisor cannot be 0

* fix another

* some test case

* update
  • Loading branch information
yoyo837 authored Oct 30, 2020
1 parent ba168ae commit 660e26e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ScrollBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
const enableScrollRange = this.getEnableScrollRange();
const enableHeightRange = this.getEnableHeightRange();

const ptg = newTop / enableHeightRange;
const ptg = enableHeightRange ? newTop / enableHeightRange : 0;
const newScrollTop = Math.ceil(ptg * enableScrollRange);
this.moveRaf = raf(() => {
onScroll(newScrollTop);
Expand All @@ -153,19 +153,22 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar

getEnableScrollRange = () => {
const { scrollHeight, height } = this.props;
return scrollHeight - height;
return scrollHeight - height || 0;
};

getEnableHeightRange = () => {
const { height } = this.props;
const spinHeight = this.getSpinHeight();
return height - spinHeight;
return height - spinHeight || 0;
};

getTop = () => {
const { scrollTop } = this.props;
const enableScrollRange = this.getEnableScrollRange();
const enableHeightRange = this.getEnableHeightRange();
if (scrollTop === 0 || enableScrollRange === 0) {
return 0;
}
const ptg = scrollTop / enableScrollRange;
return ptg * enableHeightRange;
};
Expand Down

1 comment on commit 660e26e

@vercel
Copy link

@vercel vercel bot commented on 660e26e Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.