From f2ce959d33229524b1f394a83e07b99978172d0d Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 5 Nov 2015 14:18:46 +0800 Subject: [PATCH] hide submenu on click --- components/menu/index.jsx | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/components/menu/index.jsx b/components/menu/index.jsx index 23b819c221..b86064c381 100644 --- a/components/menu/index.jsx +++ b/components/menu/index.jsx @@ -2,12 +2,41 @@ import React from 'react'; import Menu from 'rc-menu'; import animation from '../common/openAnimation'; +function noop() { +} + const AntMenu = React.createClass({ getDefaultProps() { return { - prefixCls: 'ant-menu' + prefixCls: 'ant-menu', + onClick: noop, + onOpen: noop, + onClose: noop, + }; + }, + getInitialState() { + return { + openKeys: [] }; }, + handleClick() { + this.setState({ + openKeys: [] + }); + this.props.onClick(); + }, + handleOpenKeys(e) { + this.setState({ + openKeys: e.openKeys + }); + this.props.onOpen(); + }, + handleCloseKeys(e) { + this.setState({ + openKeys: e.openKeys + }); + this.props.onClose(); + }, render() { let openAnimation = ''; switch (this.props.mode) { @@ -22,10 +51,16 @@ const AntMenu = React.createClass({ break; default: } + let props = { + openKeys: this.state.openKeys, + onClick: this.handleClick, + onOpen: this.handleOpenKeys, + onClose: this.handleCloseKeys, + }; if (this.props.mode === 'inline') { return ; } else { - return ; + return ; } } });