@@ -9,7 +9,7 @@ import placements from './placements';
9
9
import BaseMixin from '../_util/BaseMixin' ;
10
10
import { getComponent , filterEmpty , getSlot , splitAttrs , findDOMNode } from '../_util/props-util' ;
11
11
import { requestAnimationTimeout , cancelAnimationTimeout } from '../_util/requestAnimationTimeout' ;
12
- import { noop , loopMenuItemRecursively , getMenuIdFromSubMenuEventKey } from './util' ;
12
+ import { noop , getMenuIdFromSubMenuEventKey } from './util' ;
13
13
import { getTransitionProps , Transition } from '../_util/transition' ;
14
14
import { injectExtraPropsKey } from './FunctionProvider' ;
15
15
@@ -49,7 +49,7 @@ const SubMenu = {
49
49
triggerSubMenuAction : PropTypes . string ,
50
50
popupClassName : PropTypes . string ,
51
51
getPopupContainer : PropTypes . func ,
52
- forceSubMenuRender : PropTypes . looseBool ,
52
+ forceSubMenuRender : PropTypes . looseBool . def ( true ) ,
53
53
openAnimation : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
54
54
disabled : PropTypes . looseBool ,
55
55
subMenuOpenDelay : PropTypes . number . def ( 0.1 ) ,
@@ -100,21 +100,30 @@ const SubMenu = {
100
100
this . subMenuTitle = undefined ;
101
101
return {
102
102
// defaultActiveFirst: false,
103
+ childrenSelectedStatus : { } ,
103
104
} ;
104
105
} ,
106
+ computed : {
107
+ isChildrenSelected ( ) {
108
+ return Object . values ( this . childrenSelectedStatus ) . find ( status => status ) ;
109
+ } ,
110
+ } ,
105
111
mounted ( ) {
106
112
this . $nextTick ( ( ) => {
107
113
this . handleUpdated ( ) ;
108
114
} ) ;
115
+ this . updateParentMenuSelectedStatus ( ) ;
109
116
} ,
110
117
111
118
updated ( ) {
112
119
this . $nextTick ( ( ) => {
113
120
this . handleUpdated ( ) ;
114
121
} ) ;
122
+ this . updateParentMenuSelectedStatus ( ) ;
115
123
} ,
116
124
117
125
beforeUnmount ( ) {
126
+ this . updateParentMenuSelectedStatus ( false ) ;
118
127
const { eventKey } = this ;
119
128
this . __emit ( 'destroy' , eventKey ) ;
120
129
@@ -131,6 +140,18 @@ const SubMenu = {
131
140
}
132
141
} ,
133
142
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
+ } ,
134
155
handleUpdated ( ) {
135
156
const { mode, parentMenu, manualRef } = this ;
136
157
@@ -310,11 +331,11 @@ const SubMenu = {
310
331
}
311
332
} ,
312
333
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
+ // },
318
339
// isOpen () {
319
340
// return this.$props.openKeys.indexOf(this.$props.eventKey) !== -1
320
341
// },
@@ -412,7 +433,6 @@ const SubMenu = {
412
433
render ( ) {
413
434
const props = { ...this . $props , ...this . $attrs } ;
414
435
const { onEvents } = splitAttrs ( props ) ;
415
- const { rootPrefixCls } = this ;
416
436
const isOpen = props . isOpen ;
417
437
const prefixCls = this . getPrefixCls ( ) ;
418
438
const isInlineMode = props . mode === 'inline' ;
@@ -425,7 +445,7 @@ const SubMenu = {
425
445
[ this . getOpenClassName ( ) ] : isOpen ,
426
446
[ this . getActiveClassName ( ) ] : props . active || ( isOpen && ! isInlineMode ) ,
427
447
[ this . getDisabledClassName ( ) ] : props . disabled ,
428
- [ this . getSelectedClassName ( ) ] : this . isChildrenSelected ( childrenTemp ) ,
448
+ [ this . getSelectedClassName ( ) ] : this . isChildrenSelected ,
429
449
} ;
430
450
431
451
if ( ! this . internalMenuId ) {
@@ -498,7 +518,7 @@ const SubMenu = {
498
518
const popupPlacement = popupPlacementMap [ props . mode ] ;
499
519
const popupAlign = props . popupOffset ? { offset : props . popupOffset } : { } ;
500
520
let popupClassName = props . mode === 'inline' ? '' : props . popupClassName || '' ;
501
- popupClassName = `${ prefixCls } -popup ${ rootPrefixCls } ${ popupClassName } ` ;
521
+ popupClassName = `${ prefixCls } -popup ${ popupClassName } ` ;
502
522
const liProps = {
503
523
...omit ( onEvents , [ 'onClick' ] ) ,
504
524
...mouseEvents ,
0 commit comments