From cec0f45a8d84109638eb8996c71dde978093af84 Mon Sep 17 00:00:00 2001 From: ddcat1115 Date: Mon, 26 Feb 2018 18:23:30 +0800 Subject: [PATCH] improve SiderMenu --- src/components/SiderMenu/SiderMenu.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/SiderMenu/SiderMenu.js b/src/components/SiderMenu/SiderMenu.js index df3bb488..072f5cea 100644 --- a/src/components/SiderMenu/SiderMenu.js +++ b/src/components/SiderMenu/SiderMenu.js @@ -177,14 +177,17 @@ export default class SiderMenu extends PureComponent { } return ItemDom; }; - handleOpenChange = (openKeys) => { - const lastOpenKey = openKeys[openKeys.length - 1]; - const isMainMenu = this.menus.some( + isMainMenu = (key) => { + return this.menus.some( item => - lastOpenKey && (item.key === lastOpenKey || item.path === lastOpenKey), + key && (item.key === key || item.path === key), ); + } + handleOpenChange = (openKeys) => { + const lastOpenKey = openKeys[openKeys.length - 1]; + const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1; this.setState({ - openKeys: isMainMenu ? [lastOpenKey] : [...openKeys], + openKeys: moreThanOne ? [lastOpenKey] : [...openKeys], }); }; render() { -- GitLab