From 3d3cc5f7a3d32e1b212fccc4839d688e7f6e5d41 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 6 May 2016 18:07:23 +0800 Subject: [PATCH] Add control openKeys in Popup Menu --- components/menu/demo/horizontal.md | 4 ++-- components/menu/index.jsx | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/menu/demo/horizontal.md b/components/menu/demo/horizontal.md index a37582bbe0..eeba50ddae 100644 --- a/components/menu/demo/horizontal.md +++ b/components/menu/demo/horizontal.md @@ -13,13 +13,13 @@ const MenuItemGroup = Menu.ItemGroup; const App = React.createClass({ getInitialState() { return { - current: 'mail' + current: 'mail', }; }, handleClick(e) { console.log('click ', e); this.setState({ - current: e.key + current: e.key, }); }, render() { diff --git a/components/menu/index.jsx b/components/menu/index.jsx index 943e489fc6..7d860b4906 100644 --- a/components/menu/index.jsx +++ b/components/menu/index.jsx @@ -21,7 +21,7 @@ export default class Menu extends React.Component { constructor(props) { super(props); this.state = { - openKeys: [] + openKeys: ('openKeys' in props) ? props.openKeys : [], }; } componentWillReceiveProps(nextProps) { @@ -29,23 +29,28 @@ export default class Menu extends React.Component { nextProps.mode !== 'inline') { this.switchModeFromInline = true; } + if ('openKeys' in nextProps) { + this.setState({ openKeys: nextProps.openKeys }); + } } handleClick = (e) => { this.setState({ - openKeys: [] + openKeys: [], }); this.props.onClick(e); } handleOpenKeys = (e) => { - this.setState({ - openKeys: e.openKeys - }); + const { openKeys } = e; + if (!('openKeys' in this.props)) { + this.setState({ openKeys }); + } this.props.onOpen(e); } handleCloseKeys = (e) => { - this.setState({ - openKeys: e.openKeys - }); + const { openKeys } = e; + if (!('openKeys' in this.props)) { + this.setState({ openKeys }); + } this.props.onClose(e); } render() {