From cc54bef826c12454ccf832bdaccdbc5d3442b4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=A7=E6=98=8E=E8=83=A7?= <25151442+mmmml-zhao@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:19:22 +0800 Subject: [PATCH] fix: The emptyText field of the table (#49599) * fix: The emptyText field of the table when emptyText is null * test: update test case(#49599) --- components/table/InternalTable.tsx | 7 +- .../__snapshots__/empty.test.tsx.snap | 98 +++++++++++++++++++ components/table/__tests__/empty.test.tsx | 12 +++ 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/components/table/InternalTable.tsx b/components/table/InternalTable.tsx index 699384d22b..51d5384398 100644 --- a/components/table/InternalTable.tsx +++ b/components/table/InternalTable.tsx @@ -547,9 +547,10 @@ const InternalTable = ( const mergedStyle: React.CSSProperties = { ...table?.style, ...style }; - const emptyText = locale?.emptyText || renderEmpty?.('Table') || ( - - ); + const emptyText = + typeof locale?.emptyText !== 'undefined' + ? locale.emptyText + : renderEmpty?.('Table') || ; // ========================== Render ========================== const TableComponent = virtual ? RcVirtualTable : RcTable; diff --git a/components/table/__tests__/__snapshots__/empty.test.tsx.snap b/components/table/__tests__/__snapshots__/empty.test.tsx.snap index 397f1f3d20..a5f52d2f3e 100644 --- a/components/table/__tests__/__snapshots__/empty.test.tsx.snap +++ b/components/table/__tests__/__snapshots__/empty.test.tsx.snap @@ -147,6 +147,104 @@ exports[`Table renders empty table 1`] = ` `; +exports[`Table renders empty table when emptyText is null 1`] = ` +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + +
+ Column 1 + + Column 2 + + Column 3 + + Column 4 + + Column 5 + + Column 6 + + Column 7 + + Column 8 +
+
+
+
+
+
+
+
+`; + exports[`Table renders empty table with custom emptyText 1`] = `
{ }); }); + it('renders empty table when emptyText is null', () => { + const { container, asFragment } = render( + , + ); + + 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(