From 19eabb0819e1328b3d98e13cf7b3e121e68163ba Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Fri, 14 Oct 2022 11:37:48 +0800 Subject: [PATCH] fix: should support number 0 (#38006) * fix: should support number `0` * fix: should support number `0` * test: add snap * test: add snap * test: add snap * test: add snap --- components/breadcrumb/Breadcrumb.tsx | 2 +- components/breadcrumb/BreadcrumbItem.tsx | 4 +-- .../breadcrumb/__tests__/Breadcrumb.test.tsx | 11 +++++++ .../__snapshots__/Breadcrumb.test.tsx.snap | 33 +++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 5e1b5f8128..0b50c5bed1 100755 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -83,7 +83,7 @@ const Breadcrumb: BreadcrumbInterface = ({ }) => { const { getPrefixCls, direction } = React.useContext(ConfigContext); - let crumbs; + let crumbs: React.ReactNode; const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls); if (routes && routes.length > 0) { // generated by route diff --git a/components/breadcrumb/BreadcrumbItem.tsx b/components/breadcrumb/BreadcrumbItem.tsx index 944421581c..12521f738e 100644 --- a/components/breadcrumb/BreadcrumbItem.tsx +++ b/components/breadcrumb/BreadcrumbItem.tsx @@ -43,7 +43,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({ return breadcrumbItem; }; - let link; + let link: React.ReactNode; if ('href' in restProps) { link = ( @@ -60,7 +60,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({ // wrap to dropDown link = renderBreadcrumbNode(link); - if (children) { + if (children !== undefined && children !== null) { return (
  • {link} diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.tsx b/components/breadcrumb/__tests__/Breadcrumb.test.tsx index 430d25321d..a1855c3cfd 100644 --- a/components/breadcrumb/__tests__/Breadcrumb.test.tsx +++ b/components/breadcrumb/__tests__/Breadcrumb.test.tsx @@ -157,4 +157,15 @@ describe('Breadcrumb', () => { ); expect(asFragment().firstChild).toMatchSnapshot(); }); + it('should support string `0` and number `0`', () => { + const { container } = render( + + {0} + 0 + , + ); + expect(container.querySelectorAll('.ant-breadcrumb-link')[0].textContent).toBe('0'); + expect(container.querySelectorAll('.ant-breadcrumb-link')[1].textContent).toBe('0'); + expect(container.firstChild).toMatchSnapshot(); + }); }); diff --git a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap index af7651be21..afe350f4de 100644 --- a/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap +++ b/components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap @@ -323,3 +323,36 @@ exports[`Breadcrumb should support custom attribute 1`] = ` `; + +exports[`Breadcrumb should support string \`0\` and number \`0\` 1`] = ` + +`;