Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Table extends React.Component {
showHeader: PropTypes.bool,
title: PropTypes.func,
footer: PropTypes.func,
emptyText: PropTypes.func,
emptyText: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
scroll: PropTypes.object,
rowRef: PropTypes.func,
getBodyWrapper: PropTypes.func,
Expand Down Expand Up @@ -558,7 +558,7 @@ export default class Table extends React.Component {
const { emptyText, prefixCls, data } = this.props;
return !data.length ? (
<div className={`${prefixCls}-placeholder`} key="emptyText">
{emptyText()}
{(typeof emptyText === 'function') ? emptyText() : emptyText}
</div>
) : null;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ describe('Table', () => {
expect(renderToJson(wrapper)).toMatchSnapshot();
});

it('renders empty text correctly', () => {
const wrapper1 = render(createTable({ data: [], emptyText: 'No data' }));
const wrapper2 = render(createTable({ data: [], emptyText: () => 'No data' }));
expect(renderToJson(wrapper1)).toMatchSnapshot();
expect(renderToJson(wrapper2)).toMatchSnapshot();
});

it('renders without header', () => {
const wrapper = render(createTable({ showHeader: false }));
expect(renderToJson(wrapper)).toMatchSnapshot();
Expand Down
66 changes: 66 additions & 0 deletions tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,72 @@ exports[`Table renders custom cell correctly 1`] = `
</div>
`;

exports[`Table renders empty text correctly 1`] = `
<div
class="rc-table rc-table-scroll-position-left">
<div
class="rc-table-content">
<div
class="rc-table-body">
<table
class="">
<colgroup>
<col />
</colgroup>
<thead
class="rc-table-thead">
<tr>
<th
class="">
Name
</th>
</tr>
</thead>
<tbody
class="rc-table-tbody" />
</table>
</div>
<div
class="rc-table-placeholder">
No data
</div>
</div>
</div>
`;

exports[`Table renders empty text correctly 2`] = `
<div
class="rc-table rc-table-scroll-position-left">
<div
class="rc-table-content">
<div
class="rc-table-body">
<table
class="">
<colgroup>
<col />
</colgroup>
<thead
class="rc-table-thead">
<tr>
<th
class="">
Name
</th>
</tr>
</thead>
<tbody
class="rc-table-tbody" />
</table>
</div>
<div
class="rc-table-placeholder">
No data
</div>
</div>
</div>
`;

exports[`Table renders fixed header correctly 1`] = `
<div
class="rc-table rc-table-fixed-header rc-table-scroll-position-left">
Expand Down