Skip to content

Commit

Permalink
fix(layout): disable SiderContext when Sider other dom
Browse files Browse the repository at this point in the history
close #7372
  • Loading branch information
chenshuai2144 committed Jul 18, 2023
1 parent f90332a commit 4d53446
Showing 1 changed file with 75 additions and 72 deletions.
147 changes: 75 additions & 72 deletions packages/layout/src/components/SiderMenu/SiderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { GenerateStyle } from '@ant-design/pro-provider';
import { ProProvider } from '@ant-design/pro-provider';
import type { AvatarProps, SiderProps } from 'antd';
import { Avatar, Layout, Menu, Space } from 'antd';
import { SiderContext } from 'antd/es/layout/Sider';
import type { ItemType } from 'antd/lib/menu/hooks/useItems';
import classNames from 'classnames';
import type { CSSProperties } from 'react';
Expand Down Expand Up @@ -382,81 +383,83 @@ const SiderMenu: React.FC<SiderMenuProps & PrivateSiderMenuProps> = (props) => {
const menuFooterDom = menuFooterRender && menuFooterRender?.(props);

const menuDomItems = (
<>
{headerDom && (
<div
className={classNames([
classNames(`${baseClassName}-logo`, hashId, {
[`${baseClassName}-logo-collapsed`]: collapsed,
}),
])}
onClick={showSiderExtraDom ? onMenuHeaderClick : undefined}
id="logo"
style={logoStyle}
>
{headerDom}
{appsDom}
</div>
)}
{extraDom && (
<div
className={classNames([
`${baseClassName}-extra`,
!headerDom && `${baseClassName}-extra-no-logo`,
hashId,
])}
>
{extraDom}
</div>
)}
<div
style={{
flex: 1,
overflowY: 'auto',
overflowX: 'hidden',
}}
>
{menuRenderDom}
</div>
{links ? (
<div className={`${baseClassName}-links ${hashId}`.trim()}>
<Menu
inlineIndent={16}
className={`${baseClassName}-link-menu ${hashId}`.trim()}
selectedKeys={[]}
openKeys={[]}
theme={theme}
mode="inline"
items={linksMenuItems}
/>
</div>
) : null}
{showSiderExtraDom && (
<>
{actionAreaDom}
{!actionsDom && rightContentRender ? (
<div
className={classNames(`${baseClassName}-actions`, hashId, {
[`${baseClassName}-actions-collapsed`]: collapsed,
})}
>
{rightContentRender?.(props)}
</div>
) : null}
</>
)}
{menuFooterDom && (
<SiderContext.Provider value={{}}>
<>
{headerDom && (
<div
className={classNames([
classNames(`${baseClassName}-logo`, hashId, {
[`${baseClassName}-logo-collapsed`]: collapsed,
}),
])}
onClick={showSiderExtraDom ? onMenuHeaderClick : undefined}
id="logo"
style={logoStyle}
>
{headerDom}
{appsDom}
</div>
)}
{extraDom && (
<div
className={classNames([
`${baseClassName}-extra`,
!headerDom && `${baseClassName}-extra-no-logo`,
hashId,
])}
>
{extraDom}
</div>
)}
<div
className={classNames([
`${baseClassName}-footer`,
hashId,
{ [`${baseClassName}-footer-collapsed`]: collapsed },
])}
style={{
flex: 1,
overflowY: 'auto',
overflowX: 'hidden',
}}
>
{menuFooterDom}
{menuRenderDom}
</div>
)}
</>
{links ? (
<div className={`${baseClassName}-links ${hashId}`.trim()}>
<Menu
inlineIndent={16}
className={`${baseClassName}-link-menu ${hashId}`.trim()}
selectedKeys={[]}
openKeys={[]}
theme={theme}
mode="inline"
items={linksMenuItems}
/>
</div>
) : null}
{showSiderExtraDom && (
<>
{actionAreaDom}
{!actionsDom && rightContentRender ? (
<div
className={classNames(`${baseClassName}-actions`, hashId, {
[`${baseClassName}-actions-collapsed`]: collapsed,
})}
>
{rightContentRender?.(props)}
</div>
) : null}
</>
)}
{menuFooterDom && (
<div
className={classNames([
`${baseClassName}-footer`,
hashId,
{ [`${baseClassName}-footer-collapsed`]: collapsed },
])}
>
{menuFooterDom}
</div>
)}
</>
</SiderContext.Provider>
);

return stylishClassName.wrapSSR(
Expand Down

0 comments on commit 4d53446

Please sign in to comment.