From 4da414435517955d309c2f085f2bc0be250e9677 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 7 May 2016 16:06:02 +0800 Subject: [PATCH] Menu setOpenKeys --- components/menu/index.jsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/components/menu/index.jsx b/components/menu/index.jsx index 7d860b4906..3956efa93a 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' in props) ? props.openKeys : [], + openKeys: [], }; } componentWillReceiveProps(nextProps) { @@ -30,28 +30,27 @@ export default class Menu extends React.Component { this.switchModeFromInline = true; } if ('openKeys' in nextProps) { - this.setState({ openKeys: nextProps.openKeys }); + this.setOpenKeys(nextProps.openKeys); } } handleClick = (e) => { - this.setState({ - openKeys: [], - }); + this.setOpenKeys([]); this.props.onClick(e); } handleOpenKeys = (e) => { const { openKeys } = e; - if (!('openKeys' in this.props)) { - this.setState({ openKeys }); - } + this.setOpenKeys(openKeys); this.props.onOpen(e); } handleCloseKeys = (e) => { const { openKeys } = e; + this.setOpenKeys(openKeys); + this.props.onClose(e); + } + setOpenKeys(openKeys) { if (!('openKeys' in this.props)) { this.setState({ openKeys }); } - this.props.onClose(e); } render() { let openAnimation = this.props.openAnimation || this.props.openTransitionName;