Skip to content

Commit

Permalink
fix: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dream2023 committed Dec 1, 2023
1 parent 6a64928 commit 170754c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 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.16",
"version": "0.2.17",
"description": "",
"keywords": [
"dumi",
Expand Down
4 changes: 0 additions & 4 deletions src/common/styles/Responsive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ export default () => {
margin-left: 64px;
}
}
.ant-menu-inline .ant-menu-item {
padding: 0 !important;
margin: 0 !important;
}
.drawer {
.ant-menu-inline .ant-menu-item::after,
.ant-menu-vertical .ant-menu-item::after {
Expand Down
1 change: 1 addition & 0 deletions src/slots/Header/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export default function Navigation({ isMobile, responsive }: NavigationProps) {
items={items}
mode={menuMode}
css={style.nav}
style={{ height: '95%' }}
selectedKeys={[activeMenuItem]}
disabledOverflow
/>
Expand Down
21 changes: 18 additions & 3 deletions src/slots/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { UnorderedListOutlined } from '@ant-design/icons';
import { css } from '@emotion/react';
import { Affix, Col, ConfigProvider, FloatButton, Menu } from 'antd';
import { useSidebarData } from 'dumi';
import MobileMenu from 'rc-drawer';
import 'rc-drawer/assets/index.css';
import React, { FC, useCallback, useContext, useEffect, useState } from 'react';
Expand All @@ -13,6 +12,22 @@ interface SidebarState {
mobileMenuVisible: boolean;
}

function getParentPath(data: any[] | undefined, key: string) {
if (!data || !data.length) return undefined;
for (let i = 0; i < data.length; i += 1) {
if (data[i].key === key) {
return [data[i].key];
}
if (data[i].children) {
const parentPath: any = getParentPath(data[i].children, key);
if (parentPath) {
return [data[i].key, ...parentPath];
}
}
}
return null;
}

const useStyle = () => {
const { token } = useSiteToken();

Expand Down Expand Up @@ -129,7 +144,6 @@ const useStyle = () => {

const Sidebar: FC = () => {
const [sidebarState, setSidebarState] = useState<SidebarState>({ mobileMenuVisible: false });
const sidebarData = useSidebarData();
const styles = useStyle();
const {
token: { colorBgContainer }
Expand Down Expand Up @@ -161,6 +175,7 @@ const Sidebar: FC = () => {

const { mobileMenuVisible } = sidebarState;

const defaultOpenKeys = getParentPath(menuItems, selectedKey);
const menuChild = (
<ConfigProvider
theme={{
Expand All @@ -178,7 +193,7 @@ const Sidebar: FC = () => {
mode="inline"
theme={isDark ? 'dark' : 'light'}
selectedKeys={[selectedKey]}
defaultOpenKeys={sidebarData?.map(({ title }) => title).filter((item) => item) as string[]}
defaultOpenKeys={defaultOpenKeys as string[]}
/>
</ConfigProvider>
);
Expand Down

0 comments on commit 170754c

Please sign in to comment.