Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
πŸ› bug: children is null use hasChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jul 18, 2020
1 parent d68a4b0 commit 9053dad
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,23 @@ class MenuUtil {
.map((item) => this.getSubMenuOrItem(item, isChildren))
.filter((item) => item);

hasChildren = (item: MenuDataItem) => {
return (
item &&
!item.hideChildrenInMenu &&
item?.children &&
item.children.some((child) => child && !!child.name && !child.hideInMenu)
);
};

/**
* get SubMenu or Item
*/
getSubMenuOrItem = (
item: MenuDataItem,
isChildren: boolean,
): React.ReactNode => {
if (
Array.isArray(item.children) &&
!item.hideChildrenInMenu &&
item.children.some((child) => child && !!child.name && !child.hideInMenu)
) {
if (Array.isArray(item.children) && this.hasChildren(item)) {
const name = this.getIntlName(item);
const { subMenuItemRender } = this.props;
// get defaultTitle by menuItemRender
Expand Down Expand Up @@ -214,7 +219,7 @@ class MenuUtil {
onClick: () => onCollapse && onCollapse(true),
};
// ε¦‚ζžœ hideChildrenInMenu εˆ ι™€ζŽ‰ζ— η”¨ηš„ children
if (renderItemProps.hideChildrenInMenu) {
if (!this.hasChildren(item)) {
delete renderItemProps.children;
}
return menuItemRender(renderItemProps, defaultItem);
Expand Down

0 comments on commit 9053dad

Please sign in to comment.