Browse Source

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

close #38484
pull/38501/head
afc163 2 years ago
committed by GitHub
parent
commit
07462491ab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      components/result/__tests__/index.test.tsx
  2. 5
      components/result/index.tsx

7
components/result/__tests__/index.test.tsx

@ -67,4 +67,11 @@ describe('Result', () => {
warnSpy.mockRestore(); 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
components/result/index.tsx

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

Loading…
Cancel
Save