From af522ee3912b494a2592036b2435455b44a7d900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Thu, 24 Aug 2023 21:31:40 +0800 Subject: [PATCH] fix(layout): use useBreakpoint utils close https://github.com/ant-design/pro-components/issues/7564 --- packages/layout/src/ProLayout.tsx | 5 ++- .../src/components/SiderMenu/style/index.ts | 2 +- packages/utils/src/useMediaQuery/index.ts | 2 +- tests/layout/__snapshots__/demo.test.ts.snap | 18 ++++----- .../layout/__snapshots__/index.test.tsx.snap | 38 ++++++++----------- .../__snapshots__/pageContainer.test.tsx.snap | 4 +- .../pageHeaderWarp.test.tsx.snap | 8 ++-- tests/layout/index.test.tsx | 2 +- 8 files changed, 37 insertions(+), 42 deletions(-) diff --git a/packages/layout/src/ProLayout.tsx b/packages/layout/src/ProLayout.tsx index dda27c88e658..9e52e8c92f2b 100644 --- a/packages/layout/src/ProLayout.tsx +++ b/packages/layout/src/ProLayout.tsx @@ -572,9 +572,10 @@ const BaseProLayout: React.FC = (props) => { const [collapsed, onCollapse] = useMergedState( () => { - if (isMobile || colSize === 'md') return true; if (defaultCollapsed !== undefined) return defaultCollapsed; - if (isNeedOpenHash() === false) return false; + if (process.env.NODE_ENV === 'TEST') return false; + if (isMobile) return true; + if (colSize === 'md') return true; return false; }, { diff --git a/packages/layout/src/components/SiderMenu/style/index.ts b/packages/layout/src/components/SiderMenu/style/index.ts index 72618e67ab5e..b877df3626f8 100644 --- a/packages/layout/src/components/SiderMenu/style/index.ts +++ b/packages/layout/src/components/SiderMenu/style/index.ts @@ -31,7 +31,7 @@ const genSiderMenuStyle: GenerateStyle = (token) => { zIndex: 10, minHeight: '100%', }, - [`${token.antCls}-layout-sider-children`]: { + [`& ${token.antCls}-layout-sider-children`]: { position: 'relative', display: 'flex', flexDirection: 'column', diff --git a/packages/utils/src/useMediaQuery/index.ts b/packages/utils/src/useMediaQuery/index.ts index 60595488e572..757525889078 100644 --- a/packages/utils/src/useMediaQuery/index.ts +++ b/packages/utils/src/useMediaQuery/index.ts @@ -72,7 +72,7 @@ const useBreakpoint = () => { useEffect(() => { if (process.env.NODE_ENV === 'TEST') { - setColSpan((process.env.USE_MEDIA as 'xs') || 'xs'); + setColSpan((process.env.USE_MEDIA as 'md') || 'md'); return; } if (isXxl) { diff --git a/tests/layout/__snapshots__/demo.test.ts.snap b/tests/layout/__snapshots__/demo.test.ts.snap index 458950687213..f696424165a5 100644 --- a/tests/layout/__snapshots__/demo.test.ts.snap +++ b/tests/layout/__snapshots__/demo.test.ts.snap @@ -10530,7 +10530,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/customize-collaps class="ant-pro-layout-bg-list" />
@@ -20199,7 +20199,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/splitMenus.tsx co />