From 48d74a690e557eb0c0e43b55ada0f1bb15158107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 7 Jan 2025 17:58:35 +0800 Subject: [PATCH 1/2] fix: virtual scroll ref --- package.json | 2 +- src/stickyScrollBar.tsx | 2 +- src/utils/offsetUtil.ts | 20 ++++++++++++++++++++ tests/Sticky.spec.jsx | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/utils/offsetUtil.ts diff --git a/package.json b/package.json index c92cb73f3..3d992f38b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@rc-component/context": "^1.4.0", "classnames": "^2.2.5", "rc-resize-observer": "^1.1.0", - "rc-util": "^5.41.0", + "rc-util": "^5.44.3", "rc-virtual-list": "^3.14.2" }, "devDependencies": { diff --git a/src/stickyScrollBar.tsx b/src/stickyScrollBar.tsx index 759d17222..071e68494 100644 --- a/src/stickyScrollBar.tsx +++ b/src/stickyScrollBar.tsx @@ -1,12 +1,12 @@ import { useContext } from '@rc-component/context'; import classNames from 'classnames'; import addEventListener from 'rc-util/lib/Dom/addEventListener'; -import { getOffset } from 'rc-util/lib/Dom/css'; import getScrollBarSize from 'rc-util/lib/getScrollBarSize'; import * as React from 'react'; import TableContext from './context/TableContext'; import { useLayoutState } from './hooks/useFrame'; import raf from 'rc-util/lib/raf'; +import { getOffset } from './utils/offsetUtil'; interface StickyScrollBarProps { scrollBodyRef: React.RefObject; diff --git a/src/utils/offsetUtil.ts b/src/utils/offsetUtil.ts new file mode 100644 index 000000000..ffc0de17d --- /dev/null +++ b/src/utils/offsetUtil.ts @@ -0,0 +1,20 @@ +import { getDOM } from 'rc-util/lib/Dom/findDOMNode'; + +// Copy from `rc-util/Dom/css.js` +export function getOffset(node: HTMLElement | Window) { + const element = getDOM(node); + const box = element.getBoundingClientRect(); + const docElem = document.documentElement; + + // < ie8 not support win.pageXOffset, use docElem.scrollLeft instead + return { + left: + box.left + + (window.pageXOffset || docElem.scrollLeft) - + (docElem.clientLeft || document.body.clientLeft || 0), + top: + box.top + + (window.pageYOffset || docElem.scrollTop) - + (docElem.clientTop || document.body.clientTop || 0), + }; +} diff --git a/tests/Sticky.spec.jsx b/tests/Sticky.spec.jsx index 772356278..593cedc63 100644 --- a/tests/Sticky.spec.jsx +++ b/tests/Sticky.spec.jsx @@ -56,7 +56,7 @@ describe('Table.Sticky', () => { vi.useRealTimers(); }); - it('Sticky scroll', async () => { + it('Sticky scroll1', async () => { window.pageYOffset = 900; document.documentElement.scrollTop = 200; let scrollLeft = 100; From a3e55114e452b1d2a4a02c0e789970619a1d2875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 8 Jan 2025 10:42:04 +0800 Subject: [PATCH 2/2] Update Sticky.spec.jsx --- tests/Sticky.spec.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sticky.spec.jsx b/tests/Sticky.spec.jsx index 593cedc63..772356278 100644 --- a/tests/Sticky.spec.jsx +++ b/tests/Sticky.spec.jsx @@ -56,7 +56,7 @@ describe('Table.Sticky', () => { vi.useRealTimers(); }); - it('Sticky scroll1', async () => { + it('Sticky scroll', async () => { window.pageYOffset = 900; document.documentElement.scrollTop = 200; let scrollLeft = 100;