@@ -29,10 +29,10 @@ import type {
29
29
} from 'react'
30
30
import {
31
31
Children ,
32
- cloneElement ,
33
32
isValidElement ,
34
33
memo ,
35
34
useCallback ,
35
+ useContext ,
36
36
useEffect ,
37
37
useMemo ,
38
38
useReducer ,
@@ -41,6 +41,7 @@ import type { PascalToCamelCaseWithoutSuffix } from '../../../types'
41
41
import { useNavigation } from '../NavigationProvider'
42
42
import { ANIMATION_DURATION , shrinkHeight } from '../constants'
43
43
import type { PinUnPinType } from '../types'
44
+ import { ItemContext , ItemProvider } from './ItemProvider'
44
45
45
46
const RelativeDiv = styled . div `
46
47
position : relative;
@@ -325,10 +326,6 @@ type ItemProps = {
325
326
* You don't need to use this prop it's used internally to control the type of the item
326
327
*/
327
328
type ?: ItemType
328
- /**
329
- * You don't need to use this prop it's used internally to control if the item has a parent
330
- */
331
- hasParents ?: boolean
332
329
/**
333
330
* You don't need to use this prop it's used internally for pinned item to be reorganized with drag and drop
334
331
*/
@@ -372,7 +369,6 @@ export const Item = memo(
372
369
active,
373
370
noPinButton,
374
371
type = 'default' ,
375
- hasParents,
376
372
as,
377
373
disabled,
378
374
noExpand = false ,
@@ -387,6 +383,9 @@ export const Item = memo(
387
383
)
388
384
}
389
385
386
+ const itemProvider = useContext ( ItemContext )
387
+ const hasParents = ! ! itemProvider
388
+
390
389
const {
391
390
expanded,
392
391
locales,
@@ -528,14 +527,6 @@ export const Item = memo(
528
527
529
528
// This content is when the navigation is expanded
530
529
if ( expanded || ( ! expanded && animation === 'expand' ) ) {
531
- const renderChildren = Children . map ( children , child =>
532
- isValidElement < ItemProps > ( child )
533
- ? cloneElement ( child , {
534
- hasParents : true ,
535
- } )
536
- : child ,
537
- )
538
-
539
530
return (
540
531
< >
541
532
< Container
@@ -708,14 +699,18 @@ export const Item = memo(
708
699
{ children ? (
709
700
< >
710
701
{ ! noExpand ? (
711
- < Expandable
712
- opened = { internalExpanded }
713
- animationDuration = { expandableAnimationDuration }
714
- >
715
- < PaddedStack > { renderChildren } </ PaddedStack >
716
- </ Expandable >
702
+ < ItemProvider >
703
+ < Expandable
704
+ opened = { internalExpanded }
705
+ animationDuration = { expandableAnimationDuration }
706
+ >
707
+ < PaddedStack > { children } </ PaddedStack >
708
+ </ Expandable >
709
+ </ ItemProvider >
717
710
) : (
718
- < PaddedStack > { renderChildren } </ PaddedStack >
711
+ < ItemProvider >
712
+ < PaddedStack > { children } </ PaddedStack >
713
+ </ ItemProvider >
719
714
) }
720
715
</ >
721
716
) : null }
@@ -755,13 +750,7 @@ export const Item = memo(
755
750
}
756
751
placement = "right"
757
752
>
758
- { Children . map ( children , child =>
759
- isValidElement < ItemProps > ( child )
760
- ? cloneElement ( child , {
761
- hasParents : true ,
762
- } )
763
- : child ,
764
- ) }
753
+ < ItemProvider > { children } </ ItemProvider >
765
754
</ StyledMenu >
766
755
) : (
767
756
< Tooltip text = { label } placement = "right" tabIndex = { - 1 } >
0 commit comments