From b588bce7841341ec37b4bf7d6ab328363e97a55c Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 10 Nov 2022 19:02:10 +0800 Subject: [PATCH] fix: Result should hide icon when it is falsy 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 44d74cc33e7e..fb64c429421e 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 a8ec027b32cd..fd42c07a0110 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}
; };