Skip to content

Commit e97f0df

Browse files
refactor: simplify scroll state update logic in stickyScrollBar.tsx (#1318)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 3916bd3 commit e97f0df

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/stickyScrollBar.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,20 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
105105
container === window
106106
? document.documentElement.scrollTop + window.innerHeight
107107
: getOffset(container).top + (container as HTMLElement).clientHeight;
108-
109-
if (
110-
tableBottomOffset - getScrollBarSize() <= currentClientOffset ||
111-
tableOffsetTop >= currentClientOffset - offsetScroll
112-
) {
113-
setScrollState(state => ({
114-
...state,
115-
isHiddenScrollBar: true,
116-
}));
117-
} else {
118-
setScrollState(state => ({
119-
...state,
120-
isHiddenScrollBar: false,
121-
}));
122-
}
108+
setScrollState(state => ({
109+
...state,
110+
isHiddenScrollBar:
111+
tableBottomOffset - getScrollBarSize() <= currentClientOffset ||
112+
tableOffsetTop >= currentClientOffset - offsetScroll,
113+
}));
123114
});
124115
};
125116

126117
const setScrollLeft = (left: number) => {
127-
setScrollState(state => {
128-
return {
129-
...state,
130-
scrollLeft: (left / bodyScrollWidth) * bodyWidth || 0,
131-
};
132-
});
118+
setScrollState(state => ({
119+
...state,
120+
scrollLeft: bodyScrollWidth ? (left / bodyScrollWidth) * bodyWidth : 0,
121+
}));
133122
};
134123

135124
React.useImperativeHandle(ref, () => ({

0 commit comments

Comments
 (0)