Skip to content

Commit

Permalink
fix: menu title duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
dream2023 committed Dec 6, 2023
1 parent 5459d87 commit c6590f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dumi-theme-nocobase",
"version": "0.2.18",
"version": "0.2.19",
"description": "",
"keywords": [
"dumi",
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/useMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
const isSubMenu = (v: any): v is SidebarEnhanceSubType => {
return v && typeof v === 'object' && 'children' in v;
};
function processMenu(menu: SidebarEnhanceType): ItemType {
function processMenu(menu: SidebarEnhanceType, parentKey?: string): ItemType {
if (typeof menu === 'string') {
// menu: '/introduction'
return {
Expand All @@ -71,13 +71,13 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
return {
type: 'group',
label: menu.title,
key: menu.title,
children: menu.children.map(processMenu)
key: parentKey ? `${parentKey}-${menu.title}` : menu.title,
children: menu.children.map((item) => processMenu(item, menu.title))
};
}
if (isSubMenu(menu)) {
return {
key: menu.title,
key: parentKey ? `${parentKey}-${menu.title}` : menu.title,
label: menu.subTitle ? (
<span style={{ lineHeight: 1.2, display: 'block', paddingTop: 3 }}>
<span>{menu.title}</span>
Expand All @@ -93,7 +93,7 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
) : (
<span>{menu.title}</span>
),
children: menu.children.map(processMenu)
children: menu.children.map((item) => processMenu(item, menu.title))
};
}
if (isItemMenu(menu)) {
Expand All @@ -107,7 +107,7 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
}

if (!currentSidebarEnhanceData) return undefined;
return currentSidebarEnhanceData.map(processMenu);
return currentSidebarEnhanceData.map((item) => processMenu(item));
}, [after, before, currentSidebarEnhanceData, linkTitleMap, search]);

const menuItems = useMemo<MenuProps['items']>(() => {
Expand Down

0 comments on commit c6590f9

Please sign in to comment.