@@ -9,7 +9,7 @@ import placements from './placements';
99import BaseMixin from '../_util/BaseMixin' ;
1010import { getComponent , filterEmpty , getSlot , splitAttrs , findDOMNode } from '../_util/props-util' ;
1111import { requestAnimationTimeout , cancelAnimationTimeout } from '../_util/requestAnimationTimeout' ;
12- import { noop , loopMenuItemRecursively , getMenuIdFromSubMenuEventKey } from './util' ;
12+ import { noop , getMenuIdFromSubMenuEventKey } from './util' ;
1313import { getTransitionProps , Transition } from '../_util/transition' ;
1414import { injectExtraPropsKey } from './FunctionProvider' ;
1515
@@ -49,7 +49,7 @@ const SubMenu = {
4949 triggerSubMenuAction : PropTypes . string ,
5050 popupClassName : PropTypes . string ,
5151 getPopupContainer : PropTypes . func ,
52- forceSubMenuRender : PropTypes . looseBool ,
52+ forceSubMenuRender : PropTypes . looseBool . def ( true ) ,
5353 openAnimation : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
5454 disabled : PropTypes . looseBool ,
5555 subMenuOpenDelay : PropTypes . number . def ( 0.1 ) ,
@@ -100,21 +100,30 @@ const SubMenu = {
100100 this . subMenuTitle = undefined ;
101101 return {
102102 // defaultActiveFirst: false,
103+ childrenSelectedStatus : { } ,
103104 } ;
104105 } ,
106+ computed : {
107+ isChildrenSelected ( ) {
108+ return Object . values ( this . childrenSelectedStatus ) . find ( status => status ) ;
109+ } ,
110+ } ,
105111 mounted ( ) {
106112 this . $nextTick ( ( ) => {
107113 this . handleUpdated ( ) ;
108114 } ) ;
115+ this . updateParentMenuSelectedStatus ( ) ;
109116 } ,
110117
111118 updated ( ) {
112119 this . $nextTick ( ( ) => {
113120 this . handleUpdated ( ) ;
114121 } ) ;
122+ this . updateParentMenuSelectedStatus ( ) ;
115123 } ,
116124
117125 beforeUnmount ( ) {
126+ this . updateParentMenuSelectedStatus ( false ) ;
118127 const { eventKey } = this ;
119128 this . __emit ( 'destroy' , eventKey ) ;
120129
@@ -131,6 +140,18 @@ const SubMenu = {
131140 }
132141 } ,
133142 methods : {
143+ updateParentMenuSelectedStatus ( status = this . isChildrenSelected ) {
144+ if ( this . parentMenu && this . parentMenu . setChildrenSelectedStatus ) {
145+ this . parentMenu . setChildrenSelectedStatus ( this . eventKey , status ) ;
146+ }
147+ } ,
148+ setChildrenSelectedStatus ( key , status ) {
149+ if ( ! status ) {
150+ delete this . childrenSelectedStatus [ key ] ;
151+ } else {
152+ this . childrenSelectedStatus [ key ] = status ;
153+ }
154+ } ,
134155 handleUpdated ( ) {
135156 const { mode, parentMenu, manualRef } = this ;
136157
@@ -310,11 +331,11 @@ const SubMenu = {
310331 }
311332 } ,
312333
313- isChildrenSelected ( children ) {
314- const ret = { find : false } ;
315- loopMenuItemRecursively ( children , this . $props . selectedKeys , ret ) ;
316- return ret . find ;
317- } ,
334+ // isChildrenSelected(children) {
335+ // const ret = { find: false };
336+ // loopMenuItemRecursively(children, this.$props.selectedKeys, ret);
337+ // return ret.find;
338+ // },
318339 // isOpen () {
319340 // return this.$props.openKeys.indexOf(this.$props.eventKey) !== -1
320341 // },
@@ -412,7 +433,6 @@ const SubMenu = {
412433 render ( ) {
413434 const props = { ...this . $props , ...this . $attrs } ;
414435 const { onEvents } = splitAttrs ( props ) ;
415- const { rootPrefixCls } = this ;
416436 const isOpen = props . isOpen ;
417437 const prefixCls = this . getPrefixCls ( ) ;
418438 const isInlineMode = props . mode === 'inline' ;
@@ -425,7 +445,7 @@ const SubMenu = {
425445 [ this . getOpenClassName ( ) ] : isOpen ,
426446 [ this . getActiveClassName ( ) ] : props . active || ( isOpen && ! isInlineMode ) ,
427447 [ this . getDisabledClassName ( ) ] : props . disabled ,
428- [ this . getSelectedClassName ( ) ] : this . isChildrenSelected ( childrenTemp ) ,
448+ [ this . getSelectedClassName ( ) ] : this . isChildrenSelected ,
429449 } ;
430450
431451 if ( ! this . internalMenuId ) {
@@ -498,7 +518,7 @@ const SubMenu = {
498518 const popupPlacement = popupPlacementMap [ props . mode ] ;
499519 const popupAlign = props . popupOffset ? { offset : props . popupOffset } : { } ;
500520 let popupClassName = props . mode === 'inline' ? '' : props . popupClassName || '' ;
501- popupClassName = `${ prefixCls } -popup ${ rootPrefixCls } ${ popupClassName } ` ;
521+ popupClassName = `${ prefixCls } -popup ${ popupClassName } ` ;
502522 const liProps = {
503523 ...omit ( onEvents , [ 'onClick' ] ) ,
504524 ...mouseEvents ,
0 commit comments