@@ -249,6 +249,46 @@ const TopNav = ({
249
249
}
250
250
} , [ activeLevel1Id , activeLevel2Id , path ] )
251
251
252
+ const isLevel3ExactPath = ( menuWithId_ , path_ ) => {
253
+ let found = { exact : false }
254
+
255
+ // If haven't a path just return
256
+ if ( ! path_ ) return found
257
+
258
+ menuWithId_ . forEach ( level1 => {
259
+ level1 . subMenu && level1 . subMenu . forEach ( level2 => {
260
+ level2 . subMenu && level2 . subMenu . forEach ( level3 => {
261
+ if ( level3 . href && path_ . indexOf ( level3 . href ) > - 1 ) {
262
+ if ( found . exact ) {
263
+ if ( level3 . href === path_ ) found = { exact : true }
264
+ } else {
265
+ found = { exact : path_ . endsWith ( level3 . href ) }
266
+ }
267
+ }
268
+ } )
269
+ } )
270
+ level1 . secondaryMenu && level1 . secondaryMenu . forEach ( level3 => {
271
+ if ( level3 . href ) {
272
+ // Check if path have parameters
273
+ const href = level3 . href . indexOf ( '?' ) > - 1 ? level3 . href . split ( '?' ) [ 0 ] : level3 . href
274
+ if ( path_ . indexOf ( href ) > - 1 ) found = { exact : path_ . endsWith ( href ) }
275
+ }
276
+ } )
277
+ } )
278
+ return found
279
+ }
280
+
281
+ useEffect ( ( ) => {
282
+ if ( ! path || ! menuWithId ) return
283
+ // check if current path is an exact matches with level3 href
284
+ const { exact } = isLevel3ExactPath ( menuWithId , path )
285
+ if ( ! exact ) {
286
+ setActiveLevel3Id ( undefined )
287
+ setIconSelectPos ( undefined )
288
+ setShowIconSelect ( false )
289
+ }
290
+ } , [ activeLevel3Id ] )
291
+
252
292
const createHandleClickLevel3 = menuId => ( ) => {
253
293
setActiveLevel3Id ( menuId )
254
294
setIconSelectPos ( menuId )
0 commit comments