From 1ca519f474a8ac9f77f16fc572399f507c6746b0 Mon Sep 17 00:00:00 2001 From: berber1016 Date: Fri, 26 Aug 2022 15:00:25 +0800 Subject: [PATCH 1/3] fix: dynamic columns, forcescroll error --- src/Table.tsx | 4 +++- tests/Scroll.spec.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Table.tsx b/src/Table.tsx index 1a3ce7fba..9d96baae8 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -459,7 +459,9 @@ function Table(props: TableProps { + target.scrollLeft = scrollLeft; + }, 0); } } diff --git a/tests/Scroll.spec.js b/tests/Scroll.spec.js index 75c36ff31..c5e243658 100644 --- a/tests/Scroll.spec.js +++ b/tests/Scroll.spec.js @@ -114,6 +114,7 @@ describe('Table.Scroll', () => { }, }); }); + jest.runAllTimers(); expect(setScrollLeft).toHaveBeenCalledWith(undefined, 33); setScrollLeft.mockReset(); From 9e72e12e68e6a222bad8fc7b98e68d72223bca0c 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: Mon, 5 Sep 2022 14:47:01 +0800 Subject: [PATCH 2/3] chore: patch of scroll sync --- src/Table.tsx | 93 +++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/src/Table.tsx b/src/Table.tsx index 9d96baae8..5e3c8f677 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -24,60 +24,60 @@ * - All expanded props, move into expandable */ -import * as React from 'react'; -import isVisible from 'rc-util/lib/Dom/isVisible'; -import pickAttrs from 'rc-util/lib/pickAttrs'; -import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker'; import classNames from 'classnames'; -import shallowEqual from 'shallowequal'; -import warning from 'rc-util/lib/warning'; import ResizeObserver from 'rc-resize-observer'; +import isVisible from 'rc-util/lib/Dom/isVisible'; +import { isStyleSupport } from 'rc-util/lib/Dom/styleChecker'; import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize'; -import ColumnGroup from './sugar/ColumnGroup'; -import Column from './sugar/Column'; +import pickAttrs from 'rc-util/lib/pickAttrs'; +import warning from 'rc-util/lib/warning'; +import * as React from 'react'; +import shallowEqual from 'shallowequal'; +import Body from './Body'; +import ColGroup from './ColGroup'; +import { EXPAND_COLUMN } from './constant'; +import BodyContext from './context/BodyContext'; +import ExpandedRowContext from './context/ExpandedRowContext'; +import ResizeContext from './context/ResizeContext'; +import StickyContext from './context/StickyContext'; +import TableContext from './context/TableContext'; +import FixedHolder from './FixedHolder'; +import Footer, { FooterComponents } from './Footer'; +import type { SummaryProps } from './Footer/Summary'; +import Summary from './Footer/Summary'; import Header from './Header/Header'; +import useColumns from './hooks/useColumns'; +import { useLayoutState, useTimeoutLock } from './hooks/useFrame'; +import useSticky from './hooks/useSticky'; +import useStickyOffsets from './hooks/useStickyOffsets'; import type { - GetRowKey, ColumnsType, - TableComponents, - Key, + ColumnType, + CustomizeComponent, + CustomizeScrollBody, DefaultRecordType, - TriggerEventHandler, - GetComponentProps, ExpandableConfig, - LegacyExpandableProps, + ExpandableType, GetComponent, + GetComponentProps, + GetRowKey, + Key, + LegacyExpandableProps, PanelRender, - TableLayout, - ExpandableType, RowClassName, - CustomizeComponent, - ColumnType, - CustomizeScrollBody, + TableComponents, + TableLayout, TableSticky, + TriggerEventHandler, } from './interface'; -import TableContext from './context/TableContext'; -import BodyContext from './context/BodyContext'; -import Body from './Body'; -import useColumns from './hooks/useColumns'; -import { useLayoutState, useTimeoutLock } from './hooks/useFrame'; -import { getPathValue, validateValue, getColumnsKey } from './utils/valueUtil'; -import ResizeContext from './context/ResizeContext'; -import useStickyOffsets from './hooks/useStickyOffsets'; -import ColGroup from './ColGroup'; -import { getExpandableProps } from './utils/legacyUtil'; import Panel from './Panel'; -import Footer, { FooterComponents } from './Footer'; +import StickyScrollBar from './stickyScrollBar'; +import Column from './sugar/Column'; +import ColumnGroup from './sugar/ColumnGroup'; import { findAllChildrenKeys, renderExpandIcon } from './utils/expandUtil'; import { getCellFixedInfo } from './utils/fixUtil'; -import StickyScrollBar from './stickyScrollBar'; -import useSticky from './hooks/useSticky'; -import FixedHolder from './FixedHolder'; -import type { SummaryProps } from './Footer/Summary'; -import Summary from './Footer/Summary'; -import StickyContext from './context/StickyContext'; -import ExpandedRowContext from './context/ExpandedRowContext'; -import { EXPAND_COLUMN } from './constant'; +import { getExpandableProps } from './utils/legacyUtil'; +import { getColumnsKey, getPathValue, validateValue } from './utils/valueUtil'; // Used for conditions cache const EMPTY_DATA = []; @@ -458,10 +458,15 @@ function Table(props: TableProps { - target.scrollLeft = scrollLeft; - }, 0); + target.scrollLeft = scrollLeft; + + // Delay to force scroll position if not sync + // ref: https://github.com/ant-design/ant-design/issues/37179 + if (target.scrollLeft !== scrollLeft) { + setTimeout(() => { + target.scrollLeft = scrollLeft; + }, 0); + } } } @@ -615,7 +620,9 @@ function Table(props: TableProps{caption} : undefined; + caption !== null && caption !== undefined ? ( + {caption} + ) : undefined; const customizeScrollBody = getComponent(['body']) as CustomizeScrollBody; From 2036b53bb412e3e8f378e3cb6441ec9b66339601 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, 6 Sep 2022 11:12:49 +0800 Subject: [PATCH 3/3] chore: patch for types --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 006c22062..bc6fd009f 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "@types/jest": "^28.1.2", "@types/react": "^17.0.35", "@types/react-dom": "^18.0.5", + "@types/responselike": "^1.0.0", "@types/shallowequal": "^1.1.1", "@umijs/fabric": "^3.0.0", "cross-env": "^7.0.0",