Skip to content

Commit 266c10b

Browse files
berber1016zombieJ
andauthored
fix: 🐛 forceScroll error (#863)
* fix: dynamic columns, forcescroll error * chore: patch of scroll sync * chore: patch for types Co-authored-by: 二货机器人 <[email protected]>
1 parent 1839388 commit 266c10b

File tree

3 files changed

+51
-40
lines changed

3 files changed

+51
-40
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@types/jest": "^28.1.2",
6565
"@types/react": "^17.0.35",
6666
"@types/react-dom": "^18.0.5",
67+
"@types/responselike": "^1.0.0",
6768
"@types/shallowequal": "^1.1.1",
6869
"@umijs/fabric": "^3.0.0",
6970
"cross-env": "^7.0.0",

src/Table.tsx

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,60 +24,60 @@
2424
* - All expanded props, move into expandable
2525
*/
2626

27-
import * as React from 'react';
28-
import isVisible from 'rc-util/lib/Dom/isVisible';
29-
import pickAttrs from 'rc-util/lib/pickAttrs';
30-
import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker';
3127
import classNames from 'classnames';
32-
import shallowEqual from 'shallowequal';
33-
import warning from 'rc-util/lib/warning';
3428
import ResizeObserver from 'rc-resize-observer';
29+
import isVisible from 'rc-util/lib/Dom/isVisible';
30+
import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker';
3531
import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize';
36-
import ColumnGroup from './sugar/ColumnGroup';
37-
import Column from './sugar/Column';
32+
import pickAttrs from 'rc-util/lib/pickAttrs';
33+
import warning from 'rc-util/lib/warning';
34+
import * as React from 'react';
35+
import shallowEqual from 'shallowequal';
36+
import Body from './Body';
37+
import ColGroup from './ColGroup';
38+
import { EXPAND_COLUMN } from './constant';
39+
import BodyContext from './context/BodyContext';
40+
import ExpandedRowContext from './context/ExpandedRowContext';
41+
import ResizeContext from './context/ResizeContext';
42+
import StickyContext from './context/StickyContext';
43+
import TableContext from './context/TableContext';
44+
import FixedHolder from './FixedHolder';
45+
import Footer, { FooterComponents } from './Footer';
46+
import type { SummaryProps } from './Footer/Summary';
47+
import Summary from './Footer/Summary';
3848
import Header from './Header/Header';
49+
import useColumns from './hooks/useColumns';
50+
import { useLayoutState, useTimeoutLock } from './hooks/useFrame';
51+
import useSticky from './hooks/useSticky';
52+
import useStickyOffsets from './hooks/useStickyOffsets';
3953
import type {
40-
GetRowKey,
4154
ColumnsType,
42-
TableComponents,
43-
Key,
55+
ColumnType,
56+
CustomizeComponent,
57+
CustomizeScrollBody,
4458
DefaultRecordType,
45-
TriggerEventHandler,
46-
GetComponentProps,
4759
ExpandableConfig,
48-
LegacyExpandableProps,
60+
ExpandableType,
4961
GetComponent,
62+
GetComponentProps,
63+
GetRowKey,
64+
Key,
65+
LegacyExpandableProps,
5066
PanelRender,
51-
TableLayout,
52-
ExpandableType,
5367
RowClassName,
54-
CustomizeComponent,
55-
ColumnType,
56-
CustomizeScrollBody,
68+
TableComponents,
69+
TableLayout,
5770
TableSticky,
71+
TriggerEventHandler,
5872
} from './interface';
59-
import TableContext from './context/TableContext';
60-
import BodyContext from './context/BodyContext';
61-
import Body from './Body';
62-
import useColumns from './hooks/useColumns';
63-
import { useLayoutState, useTimeoutLock } from './hooks/useFrame';
64-
import { getPathValue, validateValue, getColumnsKey } from './utils/valueUtil';
65-
import ResizeContext from './context/ResizeContext';
66-
import useStickyOffsets from './hooks/useStickyOffsets';
67-
import ColGroup from './ColGroup';
68-
import { getExpandableProps } from './utils/legacyUtil';
6973
import Panel from './Panel';
70-
import Footer, { FooterComponents } from './Footer';
74+
import StickyScrollBar from './stickyScrollBar';
75+
import Column from './sugar/Column';
76+
import ColumnGroup from './sugar/ColumnGroup';
7177
import { findAllChildrenKeys, renderExpandIcon } from './utils/expandUtil';
7278
import { getCellFixedInfo } from './utils/fixUtil';
73-
import StickyScrollBar from './stickyScrollBar';
74-
import useSticky from './hooks/useSticky';
75-
import FixedHolder from './FixedHolder';
76-
import type { SummaryProps } from './Footer/Summary';
77-
import Summary from './Footer/Summary';
78-
import StickyContext from './context/StickyContext';
79-
import ExpandedRowContext from './context/ExpandedRowContext';
80-
import { EXPAND_COLUMN } from './constant';
79+
import { getExpandableProps } from './utils/legacyUtil';
80+
import { getColumnsKey, getPathValue, validateValue } from './utils/valueUtil';
8181

8282
// Used for conditions cache
8383
const EMPTY_DATA = [];
@@ -458,8 +458,15 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
458458
if (typeof target === 'function') {
459459
target(scrollLeft);
460460
} else if (target.scrollLeft !== scrollLeft) {
461-
// eslint-disable-next-line no-param-reassign
462461
target.scrollLeft = scrollLeft;
462+
463+
// Delay to force scroll position if not sync
464+
// ref: https://github.com/ant-design/ant-design/issues/37179
465+
if (target.scrollLeft !== scrollLeft) {
466+
setTimeout(() => {
467+
target.scrollLeft = scrollLeft;
468+
}, 0);
469+
}
463470
}
464471
}
465472

@@ -613,7 +620,9 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
613620
);
614621

615622
const captionElement =
616-
caption !== null && caption !== undefined ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined;
623+
caption !== null && caption !== undefined ? (
624+
<caption className={`${prefixCls}-caption`}>{caption}</caption>
625+
) : undefined;
617626

618627
const customizeScrollBody = getComponent(['body']) as CustomizeScrollBody<RecordType>;
619628

tests/Scroll.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe('Table.Scroll', () => {
114114
},
115115
});
116116
});
117+
jest.runAllTimers();
117118
expect(setScrollLeft).toHaveBeenCalledWith(undefined, 33);
118119
setScrollLeft.mockReset();
119120

0 commit comments

Comments
 (0)