Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ function Table<RecordType extends DefaultRecordType>(
scrollBodyRef={scrollBodyRef}
onScroll={onInternalScroll}
container={container}
direction={direction}
/>
)}
</>
Expand Down
36 changes: 24 additions & 12 deletions src/stickyScrollBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ interface StickyScrollBarProps {
scrollBodyRef: React.RefObject<HTMLDivElement>;
onScroll: (params: { scrollLeft?: number }) => void;
offsetScroll: number;
container: HTMLElement | Window;
container: HTMLElement | Window,
direction: string;
}

const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarProps> = (
{ scrollBodyRef, onScroll, offsetScroll, container },
{ scrollBodyRef, onScroll, offsetScroll, container, direction },
ref,
) => {
const prefixCls = useContext(TableContext, 'prefixCls');
Expand Down Expand Up @@ -74,18 +75,29 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
let left: number =
refState.current.x + event.pageX - refState.current.x - refState.current.delta;

if (left <= 0) {
left = 0;
}

if (left + scrollBarWidth >= bodyWidth) {
left = bodyWidth - scrollBarWidth;
if(direction === "ltr"){
if (left <= 0) {
left = 0;
}
if (left + scrollBarWidth >= bodyWidth) {
left = bodyWidth - scrollBarWidth;
}
onScroll({
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
});
refState.current.x = event.pageX;
}else{
if (left > 0) {
left = 0;
}
if (Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth) {
onScroll({
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
});
refState.current.x = event.pageX;
}
Copy link
Member

@afc163 afc163 Dec 30, 2024

Choose a reason for hiding this comment

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

Suggested change
if(direction === "ltr"){
if (left <= 0) {
left = 0;
}
if (left + scrollBarWidth >= bodyWidth) {
left = bodyWidth - scrollBarWidth;
}
onScroll({
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
});
refState.current.x = event.pageX;
}else{
if (left > 0) {
left = 0;
}
if (Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth) {
onScroll({
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
});
refState.current.x = event.pageX;
}
const isLTR = direction === "ltr";
// 限制滚动范围
left = Math.max(
isLTR ? 0 : -bodyWidth + scrollBarWidth,
Math.min(isLTR ? bodyWidth - scrollBarWidth : 0, left),
);
// 计算滚动位置并更新
const shouldScroll = isLTR || Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth;
if (shouldScroll) {
onScroll({
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
});
refState.current.x = event.pageX;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks
DONE.

}

onScroll({
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),
});

refState.current.x = event.pageX;
};

Expand Down