fix: The emptyText field of the table (#49599)

* fix: The emptyText field of the table
when emptyText is null

* test: update test case(#49599)
This commit is contained in:
照明胧 2024-06-26 14:19:22 +08:00 committed by GitHub
parent ff7fea18f3
commit cc54bef826
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 114 additions and 3 deletions

View File

@ -547,9 +547,10 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
const mergedStyle: React.CSSProperties = { ...table?.style, ...style };
const emptyText = locale?.emptyText || renderEmpty?.('Table') || (
<DefaultRenderEmpty componentName="Table" />
);
const emptyText =
typeof locale?.emptyText !== 'undefined'
? locale.emptyText
: renderEmpty?.('Table') || <DefaultRenderEmpty componentName="Table" />;
// ========================== Render ==========================
const TableComponent = virtual ? RcVirtualTable : RcTable;

View File

@ -147,6 +147,104 @@ exports[`Table renders empty table 1`] = `
</div>
`;
exports[`Table renders empty table when emptyText is null 1`] = `
<div
class="ant-table-wrapper"
>
<div
class="ant-spin-nested-loading"
>
<div
class="ant-spin-container"
>
<div
class="ant-table ant-table-empty"
>
<div
class="ant-table-container"
>
<div
class="ant-table-content"
>
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="ant-table-thead"
>
<tr>
<th
class="ant-table-cell"
scope="col"
>
Column 1
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 2
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 3
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 4
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 5
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 6
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 7
</th>
<th
class="ant-table-cell"
scope="col"
>
Column 8
</th>
</tr>
</thead>
<tbody
class="ant-table-tbody"
>
<tr
class="ant-table-placeholder"
>
<td
class="ant-table-cell"
colspan="8"
/>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
`;
exports[`Table renders empty table with custom emptyText 1`] = `
<div
class="ant-table-wrapper"

View File

@ -89,6 +89,18 @@ describe('Table', () => {
});
});
it('renders empty table when emptyText is null', () => {
const { container, asFragment } = render(
<Table dataSource={[]} columns={columns} pagination={false} locale={{ emptyText: null }} />,
);
expect(container.querySelector('.ant-table-placeholder>.ant-table-cell')?.hasChildNodes()).toBe(
false,
);
expect(asFragment().firstChild).toMatchSnapshot();
});
it('renders empty table with custom emptyText', () => {
const { asFragment } = render(
<Table