@@ -22,15 +22,15 @@ interface ToggleAction {
22
22
*/
23
23
interface OpenPathAction {
24
24
type : 'open-path'
25
- id : string
25
+ item : MenuItem
26
26
}
27
27
28
28
/**
29
29
* @ignore
30
30
*/
31
31
interface ClosePathAction {
32
32
type : 'close-path'
33
- id : string
33
+ item : MenuItem
34
34
}
35
35
36
36
type Action = ToggleAction | OpenPathAction | ClosePathAction
@@ -44,6 +44,7 @@ interface NestedMenuState {
44
44
items : Items
45
45
isOpen : boolean
46
46
currentPath : string [ ]
47
+ currentPathItems : MenuItem [ ]
47
48
placement : Placement
48
49
}
49
50
@@ -55,13 +56,15 @@ const reducer = produce((draft: Draft<NestedMenuState>, action: Action) => {
55
56
case 'toggle' :
56
57
draft . isOpen = ! draft . isOpen
57
58
draft . currentPath = [ ]
59
+ draft . currentPathItems = [ ]
58
60
break
59
61
60
62
case 'open-path' :
61
- draft . currentPath . push ( action . id )
63
+ draft . currentPath . push ( action . item . id )
64
+ draft . currentPathItems . push ( action . item )
62
65
break
63
66
case 'close-path' :
64
- const index = draft . currentPath . indexOf ( action . id )
67
+ const index = draft . currentPath . indexOf ( action . item . id )
65
68
draft . currentPath . splice ( index )
66
69
break
67
70
default :
@@ -100,6 +103,7 @@ export const useNestedMenu = ({
100
103
items,
101
104
isOpen,
102
105
currentPath : defaultOpenPath ,
106
+ currentPathItems : [ ] ,
103
107
placement,
104
108
} )
105
109
@@ -140,7 +144,7 @@ export const useNestedMenu = ({
140
144
if ( item . subMenu ) {
141
145
dispatch ( {
142
146
type : 'open-path' ,
143
- id : item . id ,
147
+ item,
144
148
} )
145
149
}
146
150
}
@@ -149,7 +153,7 @@ export const useNestedMenu = ({
149
153
if ( item . subMenu ) {
150
154
dispatch ( {
151
155
type : 'close-path' ,
152
- id : item . id ,
156
+ item,
153
157
} )
154
158
}
155
159
}
@@ -283,6 +287,7 @@ export const useNestedMenu = ({
283
287
} )
284
288
285
289
const getItemPath = ( item : MenuItem ) => [ ...state . currentPath , item . id ]
290
+ const getItemPathAsItems = ( item : MenuItem ) => [ ...state . currentPathItems , item ]
286
291
287
292
// still not working properly
288
293
const anchorRef = React . useRef < HTMLElement > ( )
@@ -297,6 +302,7 @@ export const useNestedMenu = ({
297
302
getCloseTriggerProps,
298
303
getToggleTriggerProps,
299
304
getItemPath,
305
+ getItemPathAsItems,
300
306
isOpen : state . isOpen ,
301
307
currentPath : state . currentPath ,
302
308
openPath,
0 commit comments