From 15d55bc3e9414857a705231649c0e84f0563c65c Mon Sep 17 00:00:00 2001 From: JounQin Date: Fri, 17 Sep 2021 11:17:29 +0800 Subject: [PATCH] feat: support ref for Table (#32136) * feat: support ref/prefix/suffix for Table close #25306 * docs: documentat Table prefix/suffix props * chore: fix lint error * refactor: remove prefix/suffix props --- components/table/Table.tsx | 22 ++++++++++++++++++++-- components/table/__tests__/Table.test.js | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 576c7ff45c..3c9ef4db69 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -99,7 +99,10 @@ export interface TableProps showSorterTooltip?: boolean | TooltipProps; } -function Table(props: TableProps) { +function InternalTable( + props: TableProps, + ref: React.MutableRefObject, +) { const { prefixCls: customizePrefixCls, className, @@ -483,7 +486,7 @@ function Table(props: TableProps) { className, ); return ( -
+
{topPaginationNode} @@ -513,6 +516,21 @@ function Table(props: TableProps) { ); } +const TableRef = React.forwardRef(InternalTable); + +type InternalTableType = typeof TableRef; + +interface TableInterface extends InternalTableType { + SELECTION_ALL: 'SELECT_ALL'; + SELECTION_INVERT: 'SELECT_INVERT'; + SELECTION_NONE: 'SELECT_NONE'; + Column: typeof Column; + ColumnGroup: typeof ColumnGroup; + Summary: typeof Summary; +} + +const Table = TableRef as TableInterface; + Table.defaultProps = { rowKey: 'key', }; diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index 8c4988e431..299724a105 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -261,4 +261,21 @@ describe('Table', () => { mount( record.key} />); expect(warnSpy).not.toBeCalled(); }); + + it('should support ref', () => { + warnSpy.mockReset(); + const columns = [ + { + title: 'Name', + key: 'name', + dataIndex: 'name', + }, + ]; + const Wrapper = () => { + const ref = React.useRef(); + return
; + }; + mount(); + expect(warnSpy).not.toBeCalled(); + }); });