Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: virtual scroll ref #1217

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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`
Copy link
Member

Choose a reason for hiding this comment

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

为啥要 copy 过来?

Copy link
Member Author

Choose a reason for hiding this comment

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

在 v6 里,rc-util 所有的 .js 后缀代码都会删掉。这个 offset 可以抽成其他方法在 rc-virtual-list 里复用,所以临时复制出来。重构的时候换个新的。

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),
};
}
Loading