From 0f83e0a4eeb72ecd34618d6ae0729a4a65329b9e 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: Thu, 17 Oct 2019 16:01:46 +0800 Subject: [PATCH] fix: should work in old version react (#19262) * fix: should work in old version react * update ci config * add version log --- .circleci/config.yml | 13 +++++++++++-- components/table/Table.tsx | 13 ++++++++----- tests/setup.js | 4 ++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a280fde28d..b3a0b805bf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -184,6 +184,7 @@ jobs: command: npm test -- -w 1 -u environment: LIB_DIR: dist + REACT: 15 test_lib_15: <<: *container_config @@ -196,6 +197,7 @@ jobs: command: npm test -- -w 1 -u environment: LIB_DIR: lib + REACT: 15 test_es_15: <<: *container_config @@ -208,6 +210,7 @@ jobs: command: npm test -- -w 1 -u environment: LIB_DIR: es + REACT: 15 test_dom_15: <<: *container_config @@ -216,7 +219,10 @@ jobs: - checkout - *attach_workspace - *install_react - - run: npm test -- -w 1 -u + - run: + command: npm test -- -w 1 -u + environment: + REACT: 15 test_node_15: <<: *container_config @@ -225,7 +231,10 @@ jobs: - checkout - *attach_workspace - *install_react - - run: npm run test-node -- -w 1 -u + - run: + command: npm run test-node -- -w 1 -u + environment: + REACT: 15 check_metadata: <<: *container_config diff --git a/components/table/Table.tsx b/components/table/Table.tsx index b03d238dbe..5a15e011cb 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -239,11 +239,10 @@ class Table extends React.Component, TableState> { row: React.ComponentType; - rcTable: React.RefObject; + rcTable: any; constructor(props: TableProps) { super(props); - this.rcTable = React.createRef(); const { expandedRowRender, columns: columnsProp = [] } = props; @@ -286,6 +285,10 @@ class Table extends React.Component, TableState> { } } + setTableRef = (table: any) => { + this.rcTable = table; + }; + getCheckboxPropsByItem = (item: T, index: number) => { const rowSelection = getRowSelection(this.props); if (!rowSelection.getCheckboxProps) { @@ -535,7 +538,7 @@ class Table extends React.Component, TableState> { generatePopupContainerFunc = (getPopupContainer: TableProps['getPopupContainer']) => { const { scroll } = this.props; - const table = this.rcTable.current; + const table = this.rcTable; if (getPopupContainer) { return getPopupContainer; } @@ -547,7 +550,7 @@ class Table extends React.Component, TableState> { const { scroll } = this.props; if (scroll && scroll.scrollToFirstRowOnChange !== false) { scrollTo(0, { - getContainer: () => this.rcTable.current.bodyTable, + getContainer: () => this.rcTable.bodyTable, }); } }; @@ -1285,7 +1288,7 @@ class Table extends React.Component, TableState> { return ( {