Skip to content

Commit ed2cac5

Browse files
authored
fix: scale scroll (#280)
1 parent f10c8e8 commit ed2cac5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/ScrollBar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
142142
} = stateRef.current;
143143
raf.cancel(moveRafId);
144144

145-
const scale = containerSize / scrollbarRef.current.getBoundingClientRect().height;
145+
const rect = scrollbarRef.current.getBoundingClientRect();
146+
const scale = containerSize / (horizontal ? rect.width : rect.height);
146147

147148
if (stateDragging) {
148149
const offset = (getPageXY(e, horizontal) - statePageY) * scale;
@@ -193,7 +194,7 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
193194

194195
React.useEffect(() => {
195196
delayHidden();
196-
return () => {
197+
return () => {
197198
clearTimeout(visibleTimeoutRef.current);
198199
};
199200
}, [scrollOffset]);

tests/scrollWidth.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('List.scrollWidth', () => {
3737
},
3838
clientHeight: {
3939
get() {
40-
return holderWidth;
40+
return holderHeight;
4141
},
4242
},
4343
getBoundingClientRect() {

0 commit comments

Comments
 (0)