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
This commit is contained in:
lijianan 2022-10-14 11:37:48 +08:00 committed by GitHub
parent 02b1176c43
commit 19eabb0819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 3 deletions

View File

@ -83,7 +83,7 @@ const Breadcrumb: BreadcrumbInterface = ({
}) => { }) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext); const { getPrefixCls, direction } = React.useContext(ConfigContext);
let crumbs; let crumbs: React.ReactNode;
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls); const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
if (routes && routes.length > 0) { if (routes && routes.length > 0) {
// generated by route // generated by route

View File

@ -43,7 +43,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({
return breadcrumbItem; return breadcrumbItem;
}; };
let link; let link: React.ReactNode;
if ('href' in restProps) { if ('href' in restProps) {
link = ( link = (
<a className={`${prefixCls}-link`} {...restProps}> <a className={`${prefixCls}-link`} {...restProps}>
@ -60,7 +60,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({
// wrap to dropDown // wrap to dropDown
link = renderBreadcrumbNode(link); link = renderBreadcrumbNode(link);
if (children) { if (children !== undefined && children !== null) {
return ( return (
<li> <li>
{link} {link}

View File

@ -157,4 +157,15 @@ describe('Breadcrumb', () => {
); );
expect(asFragment().firstChild).toMatchSnapshot(); expect(asFragment().firstChild).toMatchSnapshot();
}); });
it('should support string `0` and number `0`', () => {
const { container } = render(
<Breadcrumb>
<Breadcrumb.Item>{0}</Breadcrumb.Item>
<Breadcrumb.Item>0</Breadcrumb.Item>
</Breadcrumb>,
);
expect(container.querySelectorAll('.ant-breadcrumb-link')[0].textContent).toBe('0');
expect(container.querySelectorAll('.ant-breadcrumb-link')[1].textContent).toBe('0');
expect(container.firstChild).toMatchSnapshot();
});
}); });

View File

@ -323,3 +323,36 @@ exports[`Breadcrumb should support custom attribute 1`] = `
</ol> </ol>
</nav> </nav>
`; `;
exports[`Breadcrumb should support string \`0\` and number \`0\` 1`] = `
<nav
class="ant-breadcrumb"
>
<ol>
<li>
<span
class="ant-breadcrumb-link"
>
0
</span>
<span
class="ant-breadcrumb-separator"
>
/
</span>
</li>
<li>
<span
class="ant-breadcrumb-link"
>
0
</span>
<span
class="ant-breadcrumb-separator"
>
/
</span>
</li>
</ol>
</nav>
`;