@@ -34,19 +34,23 @@ export const CNavContext = createContext({} as ContextProps)
3434
3535const recursiveClone = ( children : ReactNode , id ?: string , updateId ?: boolean ) : ReactNode => {
3636 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+ ) {
3846 return child
3947 }
4048
4149 const _id = id ? ( updateId ? `${ id } .${ index } ` : `${ id } ` ) : `${ index } `
4250
4351 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 ,
5054 children : recursiveClone (
5155 child . props . children ,
5256 _id ,
@@ -57,10 +61,7 @@ const recursiveClone = (children: ReactNode, id?: string, updateId?: boolean): R
5761 }
5862
5963 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 ,
6465 } )
6566 } )
6667}
0 commit comments