From 7d5db31e67564962fb96238bc73ff6e14abf7933 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Wed, 14 Feb 2018 12:27:00 +0800 Subject: [PATCH] Fix table custom spin indicator Fix #9355 --- components/table/Table.tsx | 25 ++++++++++++------------ components/table/__tests__/Table.test.js | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index dafe021c25..7c39867b64 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -17,6 +17,7 @@ import Column from './Column'; import ColumnGroup from './ColumnGroup'; import createBodyRow from './createBodyRow'; import { flatArray, treeMap, flatFilter, normalizeColumns } from './util'; +import { SpinProps } from '../spin'; import { TableProps, TableState, @@ -915,9 +916,9 @@ export default class Table extends React.Component, TableState< } } - renderTable = (contextLocale: TableLocale) => { + renderTable = (contextLocale: TableLocale, loading: SpinProps) => { const locale = { ...contextLocale, ...this.props.locale }; - const { style, loading, className, prefixCls, showHeader, ...restProps } = this.props; + const { style, className, prefixCls, showHeader, ...restProps } = this.props; const data = this.getCurrentPageData(); const expandIconAsCell = this.props.expandedRowRender && this.props.expandIconAsCell !== false; @@ -953,7 +954,7 @@ export default class Table extends React.Component, TableState< className={classString} expandIconColumnIndex={expandIconColumnIndex} expandIconAsCell={expandIconAsCell} - emptyText={!loading && locale.emptyText} + emptyText={!loading.spinning && locale.emptyText} /> ); } @@ -962,12 +963,19 @@ export default class Table extends React.Component, TableState< const { style, className, prefixCls } = this.props; const data = this.getCurrentPageData(); + let loading = this.props.loading as SpinProps; + if (typeof loading === 'boolean') { + loading = { + spinning: loading, + }; + } + const table = ( - {this.renderTable} + {(locale) => this.renderTable(locale, loading)} ); @@ -976,13 +984,6 @@ export default class Table extends React.Component, TableState< const paginationPatchClass = (this.hasPagination() && data && data.length !== 0) ? `${prefixCls}-with-pagination` : `${prefixCls}-without-pagination`; - let loading = this.props.loading; - if (typeof loading === 'boolean') { - loading = { - spinning: loading, - }; - } - return (
extends React.Component, TableState< > {table} {this.renderPagination()} diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index 20d97f760f..a535eeb63f 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -67,6 +67,7 @@ describe('Table', () => { }; const wrapper = mount(); expect(wrapper.find('.ant-spin')).toHaveLength(0); + expect(wrapper.find('.ant-table-placeholder').text()).not.toEqual(''); loading.spinning = true; wrapper.setProps({ loading });