Skip to content

Commit

Permalink
fix: virtual scroll ref (#1217)
Browse files Browse the repository at this point in the history
* fix: virtual scroll ref

* Update Sticky.spec.jsx
  • Loading branch information
zombieJ authored Jan 8, 2025
1 parent b12a943 commit b3d5c37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/stickyScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLDivElement>;
Expand Down
20 changes: 20 additions & 0 deletions src/utils/offsetUtil.ts
Original file line number Diff line number Diff line change
@@ -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),
};
}

0 comments on commit b3d5c37

Please sign in to comment.