From d8ea555ee871f456d984d97b0086add3904245cf Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Mon, 7 Nov 2016 11:00:43 +0800 Subject: [PATCH] docs: update menu demo --- components/menu/demo/sider-current.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/components/menu/demo/sider-current.md b/components/menu/demo/sider-current.md index 9a6b78f33e..dc676add39 100755 --- a/components/menu/demo/sider-current.md +++ b/components/menu/demo/sider-current.md @@ -29,19 +29,26 @@ const Sider = React.createClass({ }; }, handleClick(e) { - console.log('click ', e); + console.log('Clicked: ', e); this.setState({ current: e.key }); }, onOpenChange(openKeys) { - const latestOpenKey = openKeys.find(key => !(this.state.openKeys.indexOf(key) > -1)); - this.setState({ openKeys: this.getKeyPath(latestOpenKey) }); + const state = this.state; + const latestOpenKey = openKeys.find(key => !(state.openKeys.indexOf(key) > -1)); + const latestCloseKey = state.openKeys.find(key => !(openKeys.indexOf(key) > -1)); + + let nextOpenKeys = []; + if (latestOpenKey) { + nextOpenKeys = this.getAncestorKeys(latestOpenKey).concat(latestOpenKey); + } + if (latestCloseKey) { + nextOpenKeys = this.getAncestorKeys(latestCloseKey); + } + this.setState({ openKeys: nextOpenKeys }); }, - getKeyPath(key) { + getAncestorKeys(key) { const map = { - sub1: ['sub1'], - sub2: ['sub2'], - sub3: ['sub2', 'sub3'], - sub4: ['sub4'], + sub3: ['sub2'], }; return map[key] || []; },