From b3d5c3750497fef470979096a8e3f378ff3af298 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 17:22:16 +0800 Subject: [PATCH] fix: virtual scroll ref (#1217) * fix: virtual scroll ref * Update Sticky.spec.jsx --- package.json | 2 +- src/stickyScrollBar.tsx | 2 +- src/utils/offsetUtil.ts | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/utils/offsetUtil.ts diff --git a/package.json b/package.json index c92cb73f..3d992f38 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 759d1722..071e6849 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 00000000..ffc0de17 --- /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), + }; +}