diff --git a/assets/index.less b/assets/index.less index 10de96bf..6fb28966 100644 --- a/assets/index.less +++ b/assets/index.less @@ -45,6 +45,10 @@ transform: translateZ(0); } + &-submenu-selected { + background-color: #eaf8fe; + } + & > li&-submenu { padding: 0; } diff --git a/src/Menu.jsx b/src/Menu.jsx index c5df00a9..c4860d2c 100644 --- a/src/Menu.jsx +++ b/src/Menu.jsx @@ -52,7 +52,9 @@ const Menu = React.createClass({ openKeys = props.openKeys || []; } return { - selectedKeys, openKeys, + selectedKeys, + openKeys, + keyPath: [], }; }, @@ -125,6 +127,9 @@ const Menu = React.createClass({ }, onClick(e) { + this.setState({ + keyPath: [...e.keyPath], + }); const props = this.props; props.onClick(e); }, @@ -214,7 +219,8 @@ const Menu = React.createClass({ openKeys: state.openKeys, open: state.openKeys.indexOf(key) !== -1, selectedKeys: state.selectedKeys, - selected: state.selectedKeys.indexOf(key) !== -1, + keyPath: state.keyPath, + selected: state.selectedKeys.indexOf(key) !== -1 || state.keyPath.indexOf(key) !== -1, openSubMenuOnMouseEnter: this.props.openSubMenuOnMouseEnter, }; return this.renderCommonMenuItem(c, i, subIndex, extraProps); diff --git a/src/SubMenu.jsx b/src/SubMenu.jsx index 11740c2d..d0c0e46a 100644 --- a/src/SubMenu.jsx +++ b/src/SubMenu.jsx @@ -245,6 +245,10 @@ const SubMenu = React.createClass({ return `${this.getPrefixCls()}-disabled`; }, + getSelectedClassName() { + return `${this.getPrefixCls()}-selected`; + }, + getOpenClassName() { return `${this.props.rootPrefixCls}-submenu-open`; }, @@ -312,6 +316,7 @@ const SubMenu = React.createClass({ onDeselect: this.onDeselect, onDestroy: this.onDestroy, selectedKeys: props.selectedKeys, + keyPath: props.keyPath, eventKey: `${props.eventKey}-menu-`, openKeys: props.openKeys, openTransitionName: props.openTransitionName, @@ -339,6 +344,7 @@ const SubMenu = React.createClass({ classes[this.getOpenClassName()] = this.props.open; classes[this.getActiveClassName()] = props.active; classes[this.getDisabledClassName()] = props.disabled; + classes[this.getSelectedClassName()] = props.selected; this._menuId = this._menuId || guid(); classes[prefixCls] = true; classes[`${prefixCls}-${props.mode}`] = 1; diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 69a11ab4..959bb49e 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -55,8 +55,9 @@ const SubPopupMenu = React.createClass({ const extraProps = { openKeys: props.openKeys, selectedKeys: props.selectedKeys, + keyPath: props.keyPath, open: props.openKeys.indexOf(key) !== -1, - selected: props.selectedKeys.indexOf(key) !== -1, + selected: props.selectedKeys.indexOf(key) !== -1 || props.keyPath.indexOf(key) !== -1, openSubMenuOnMouseEnter: true, }; return this.renderCommonMenuItem(c, i, subIndex, extraProps);