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

Commit

Permalink
🐛 bug: fix openkeys error in defaultOpenKeys (#557)
Browse files Browse the repository at this point in the history
* 📸 snapshots: update snapshot

* 🐛 bug: fix openkeys error in defaultOpenKeys
  • Loading branch information
chenshuai2144 committed Jul 13, 2020
1 parent 6cc0eb8 commit 5ec50ae
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 101 deletions.
13 changes: 7 additions & 6 deletions src/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ const BaseMenu: React.FC<BaseMenuProps> = (props) => {
);

useEffect(() => {
setPostMenuData(menuData);
if (menu.defaultOpenAll || propsOpenKeys === false || flatMenuKeys.length) {
return;
}
Expand Down Expand Up @@ -367,18 +366,20 @@ const BaseMenu: React.FC<BaseMenuProps> = (props) => {

useEffect(() => {
if (splitMenus && openKeys) {
const key = [...openKeys].shift();
const keys = getSelectedMenuKeys(
location.pathname || '/',
menuData || [],
);
const [key] = keys;
if (key) {
const postData =
menuData?.find((item) => item.key === key)?.children || [];
setPostMenuData(postData);
return;
}
}
if (!splitMenus) {
setPostMenuData(menuData);
}
}, [(openKeys || []).join('-'), splitMenus]);
setPostMenuData(menuData);
}, [pathname, splitMenus, flatMenuKeys.join('-')]);

// 这次 openKeys === false 的时候的情况,这种情况下帮用户选中一次
// 第二次以后不再关系,所以用了 defaultOpenKeys
Expand Down
68 changes: 22 additions & 46 deletions tests/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ exports[`BasicLayout 🥩 base use 1`] = `
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
/>
</section>
</section>
</div>
Expand Down Expand Up @@ -197,11 +193,7 @@ exports[`BasicLayout 🥩 contentStyle should change dom 1`] = `
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
style="padding:56px"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
/>
</section>
</section>
</div>
Expand Down Expand Up @@ -300,11 +292,7 @@ exports[`BasicLayout 🥩 menuDataRender change date 1`] = `
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
/>
</section>
</section>
</div>
Expand Down Expand Up @@ -423,11 +411,7 @@ exports[`BasicLayout 🥩 menuDataRender change date 2`] = `
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
/>
</section>
</section>
</div>
Expand Down Expand Up @@ -528,31 +512,27 @@ exports[`BasicLayout 🥩 support loading 1`] = `
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
style="padding-top: 100px; text-align: center;"
>
<div
style="padding-top: 100px; text-align: center;"
class="ant-spin ant-spin-lg ant-spin-spinning"
>
<div
class="ant-spin ant-spin-lg ant-spin-spinning"
<span
class="ant-spin-dot ant-spin-dot-spin"
>
<span
class="ant-spin-dot ant-spin-dot-spin"
>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
</span>
</div>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
</span>
</div>
</div>
</main>
Expand Down Expand Up @@ -707,11 +687,7 @@ exports[`BasicLayout 🥩 support menuDataRender 1`] = `
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
/>
</section>
</section>
</div>
Expand Down
90 changes: 41 additions & 49 deletions tests/__tests__/__snapshots__/pageHeaderWarp.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,40 +115,36 @@ exports[`BasicLayout base use 1`] = `
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
class="ant-pro-page-container"
>
<div
class="ant-pro-page-container"
class="ant-pro-page-container-warp"
>
<div
class="ant-pro-page-container-warp"
class="ant-page-header ant-page-header-ghost"
>
<div
class="ant-page-header ant-page-header-ghost"
class="ant-page-header-heading"
>
<div
class="ant-page-header-heading"
class="ant-page-header-heading-left"
>
<div
class="ant-page-header-heading-left"
<span
class="ant-page-header-heading-title"
title="welcome"
>
<span
class="ant-page-header-heading-title"
title="welcome"
>
welcome
</span>
</div>
welcome
</span>
</div>
</div>
</div>
</div>
<div
class="ant-pro-grid-content"
>
<div
class="ant-pro-grid-content"
>
<div
class="ant-pro-grid-content-children"
/>
</div>
class="ant-pro-grid-content-children"
/>
</div>
</div>
</main>
Expand Down Expand Up @@ -272,61 +268,57 @@ exports[`BasicLayout content is text 1`] = `
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
class="ant-pro-page-container"
>
<div
class="ant-pro-page-container"
class="ant-pro-page-container-warp"
>
<div
class="ant-pro-page-container-warp"
class="ant-page-header ant-page-header-ghost"
>
<div
class="ant-page-header ant-page-header-ghost"
class="ant-page-header-heading"
>
<div
class="ant-page-header-heading"
class="ant-page-header-heading-left"
>
<div
class="ant-page-header-heading-left"
<span
class="ant-page-header-heading-title"
title="welcome"
>
<span
class="ant-page-header-heading-title"
title="welcome"
>
welcome
</span>
</div>
welcome
</span>
</div>
</div>
<div
class="ant-page-header-content"
>
<div
class="ant-page-header-content"
class="ant-pro-page-container-detail"
>
<div
class="ant-pro-page-container-detail"
class="ant-pro-page-container-main"
>
<div
class="ant-pro-page-container-main"
class="ant-pro-page-container-row"
>
<div
class="ant-pro-page-container-row"
class="ant-pro-page-container-content"
>
<div
class="ant-pro-page-container-content"
>
just so so
</div>
just so so
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class="ant-pro-grid-content"
>
<div
class="ant-pro-grid-content"
>
<div
class="ant-pro-grid-content-children"
/>
</div>
class="ant-pro-grid-content-children"
/>
</div>
</div>
</main>
Expand Down

0 comments on commit 5ec50ae

Please sign in to comment.