Skip to content

Commit

Permalink
fix: Result should hide icon when it is falsy
Browse files Browse the repository at this point in the history
close #38484
  • Loading branch information
afc163 committed Nov 10, 2022
1 parent 8af0b4f commit c3767f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/result/__tests__/index.test.tsx
Expand Up @@ -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);
});
});
5 changes: 5 additions & 0 deletions components/result/index.tsx
Expand Up @@ -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 icon;
}

return <div className={className}>{icon || iconNode}</div>;
};

Expand Down

0 comments on commit c3767f3

Please sign in to comment.