From df977892f7db86b2a9be9ca2de236bca609809be Mon Sep 17 00:00:00 2001 From: Jan William Date: Sat, 19 Apr 2025 14:41:44 +0800 Subject: [PATCH] fix: table forceScroll setTimeout issue --- src/Table.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Table.tsx b/src/Table.tsx index c617ba494..11803223e 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -417,7 +417,7 @@ function Table( const [setScrollTarget, getScrollTarget] = useTimeoutLock(null); - function forceScroll(scrollLeft: number, target: HTMLDivElement | ((left: number) => void)) { + function forceScroll(scrollLeft: number, target: HTMLDivElement & {_scrollTimeout?: number | null} | ((left: number) => void)) { if (!target) { return; } @@ -426,11 +426,17 @@ function Table( } else if (target.scrollLeft !== scrollLeft) { target.scrollLeft = scrollLeft; + if (target._scrollTimeout) { + window.clearTimeout(target._scrollTimeout); + target._scrollTimeout = null; + } + // Delay to force scroll position if not sync // ref: https://github.com/ant-design/ant-design/issues/37179 if (target.scrollLeft !== scrollLeft) { - setTimeout(() => { + target._scrollTimeout = setTimeout(() => { target.scrollLeft = scrollLeft; + target._scrollTimeout = null; }, 0); } }