fix: skeleton cannot dispaly without children and loading props : Skeleton(...) return nothing (#34872)

* fix: skeleton cannot dispaly without children

* [CodeFactor] Apply fixes to commit 0b4a968

[ci skip] [skip ci]

* fix: update skeleton

Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
Albert Zhang 2022-04-07 17:55:30 +08:00 committed by GitHub
parent d49013468a
commit b3e66762d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -161,7 +161,7 @@ const Skeleton = (props: SkeletonProps) => {
</div>
);
}
return children as React.ReactElement;
return typeof children !== 'undefined' ? (children as React.ReactElement) : null;
};
Skeleton.defaultProps = {

View File

@ -481,6 +481,8 @@ exports[`Skeleton rtl render component should be rendered correctly in RTL direc
</div>
`;
exports[`Skeleton should display without children and falsy loading props 1`] = `null`;
exports[`Skeleton should round title and paragraph 1`] = `
<div
class="ant-skeleton ant-skeleton-round"

View File

@ -34,6 +34,16 @@ describe('Skeleton', () => {
expect(wrapperSmall.render()).toMatchSnapshot();
});
it('should display without children and falsy loading props', () => {
const wrapper = mount(<Skeleton loading={false} />);
expect(wrapper.render()).toMatchSnapshot();
});
it('should display with empty children and falsy loading props', () => {
const wrapper = mount(<Skeleton loading={false}>{0}</Skeleton>);
expect(wrapper.text()).toBe('0');
});
it('should display children', () => {
const wrapper = mount(<Skeleton loading={false}>{[1, 2, 3]}</Skeleton>);
expect(wrapper.text()).toBe('123');