Skip to content

Commit

Permalink
fix(breadcrumbs): filter null, undefined, and null string (#1856)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Feb 22, 2022
1 parent e367f16 commit 147617a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from 'classnames';
import React from 'react';
import { usePrefixCls } from '@gio-design/utils';
import { isNil } from 'lodash';
import WithRef from '../utils/withRef';
import BreadcrumbsProps from './interface';

Expand All @@ -9,12 +10,14 @@ const Breadcrumbs = WithRef<HTMLElement, BreadcrumbsProps>(
const prefixCls = usePrefixCls('breadcrumbs');
const classes = classNames([className, prefixCls]);

const breadcrumbsItems = React.Children.toArray(children).map((child, index) => (
// eslint-disable-next-line react/no-array-index-key
<li className={`${prefixCls}__li`} key={`${prefixCls}-li-${index}`}>
{child}
</li>
));
const breadcrumbsItems = React.Children.toArray(children)
.filter((child) => !isNil(child) || child !== '')
.map((child, index) => (
// eslint-disable-next-line react/no-array-index-key
<li className={`${prefixCls}__li`} key={`${prefixCls}-li-${index}`}>
{child}
</li>
));

return (
<nav ref={ref} className={classes} aria-label="breadcrumbs" data-testid="breadcrumbs" {...otherProps}>
Expand Down

1 comment on commit 147617a

@vercel
Copy link

@vercel vercel bot commented on 147617a Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.