@@ -34,19 +34,23 @@ export const CNavContext = createContext({} as ContextProps)
34
34
35
35
const recursiveClone = ( children : ReactNode , id ?: string , updateId ?: boolean ) : ReactNode => {
36
36
return React . Children . map ( children , ( child : ReactNode , index : number ) => {
37
- if ( ! React . isValidElement ( child ) ) {
37
+ if (
38
+ ! React . isValidElement ( child ) ||
39
+ // @ts -expect-error the `children` exist in each component. TODO: resolve
40
+ ( child . type . displayName !== 'CNavGroup' &&
41
+ // @ts -expect-error the `children` exist in each component. TODO: resolve
42
+ child . type . displayName !== 'CNavLink' &&
43
+ // @ts -expect-error the `children` exist in each component. TODO: resolve
44
+ child . type . displayName !== 'CNavItem' )
45
+ ) {
38
46
return child
39
47
}
40
48
41
49
const _id = id ? ( updateId ? `${ id } .${ index } ` : `${ id } ` ) : `${ index } `
42
50
43
51
if ( child . props && child . props . children ) {
44
- child = React . cloneElement ( child , {
45
- // @ts -expect-error the `displayName` exist in each component. TODO: resolve
46
- ...( ( child . type . displayName === 'CNavGroup' || child . type . displayName === 'CNavLink' ) && {
47
- idx : _id ,
48
- } ) ,
49
- // @ts -expect-error the `children` exist in each component. TODO: resolve
52
+ return React . cloneElement ( child as ReactElement < any > , {
53
+ idx : _id ,
50
54
children : recursiveClone (
51
55
child . props . children ,
52
56
_id ,
@@ -57,10 +61,7 @@ const recursiveClone = (children: ReactNode, id?: string, updateId?: boolean): R
57
61
}
58
62
59
63
return React . cloneElement ( child as ReactElement < any > , {
60
- // @ts -expect-error the `displayName` exist in each component. TODO: resolve
61
- ...( ( child . type . displayName === 'CNavGroup' || child . type . displayName === 'CNavLink' ) && {
62
- idx : _id ,
63
- } ) ,
64
+ idx : _id ,
64
65
} )
65
66
} )
66
67
}
0 commit comments