From 07462491ab53c8d34171325b21f07580b3324362 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 10 Nov 2022 19:27:36 +0800 Subject: [PATCH] fix: Result should hide icon when it is falsy (#38488) close #38484 --- components/result/__tests__/index.test.tsx | 7 +++++++ components/result/index.tsx | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/components/result/__tests__/index.test.tsx b/components/result/__tests__/index.test.tsx index 44d74cc33e..fb64c42942 100644 --- a/components/result/__tests__/index.test.tsx +++ b/components/result/__tests__/index.test.tsx @@ -67,4 +67,11 @@ describe('Result', () => { warnSpy.mockRestore(); }); + + it('should hide icon by setting icon to false or null', () => { + const { container } = render(); + expect(container.querySelectorAll('.ant-result-icon')).toHaveLength(0); + const { container: container2 } = render(); + expect(container2.querySelectorAll('.ant-result-icon')).toHaveLength(0); + }); }); diff --git a/components/result/index.tsx b/components/result/index.tsx index a8ec027b32..fd42c07a01 100644 --- a/components/result/index.tsx +++ b/components/result/index.tsx @@ -73,10 +73,15 @@ const Icon: React.FC = ({ prefixCls, icon, status }) => { ); } + const iconNode = React.createElement( IconMap[status as Exclude], ); + if (icon === null || icon === false) { + return null; + } + return
{icon || iconNode}
; };