fix: Result should hide icon when it is falsy (#38488)

close #38484
This commit is contained in:
afc163 2022-11-10 19:27:36 +08:00 committed by GitHub
parent d5e3f1e6de
commit 07462491ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -67,4 +67,11 @@ describe('Result', () => {
warnSpy.mockRestore();
});
it('should hide icon by setting icon to false or null', () => {
const { container } = render(<Result title="404" icon={null} />);
expect(container.querySelectorAll('.ant-result-icon')).toHaveLength(0);
const { container: container2 } = render(<Result title="404" icon={false} />);
expect(container2.querySelectorAll('.ant-result-icon')).toHaveLength(0);
});
});

View File

@ -73,10 +73,15 @@ const Icon: React.FC<IconProps> = ({ prefixCls, icon, status }) => {
</div>
);
}
const iconNode = React.createElement(
IconMap[status as Exclude<ResultStatusType, ExceptionStatusType>],
);
if (icon === null || icon === false) {
return null;
}
return <div className={className}>{icon || iconNode}</div>;
};