@@ -89,7 +89,7 @@ const SideNavMenu = React.forwardRef<HTMLElement, SideNavMenuProps>(
89
89
const className = cx ( {
90
90
[ `${ prefix } --side-nav__item` ] : true ,
91
91
[ `${ prefix } --side-nav__item--active` ] :
92
- isActive || ( hasActiveChild ( children ) && ! isExpanded ) ,
92
+ isActive || ( hasActiveDescendant ( children ) && ! isExpanded ) ,
93
93
[ `${ prefix } --side-nav__item--icon` ] : IconElement ,
94
94
[ `${ prefix } --side-nav__item--large` ] : large ,
95
95
[ customClassName as string ] : ! ! customClassName ,
@@ -200,7 +200,7 @@ SideNavMenu.propTypes = {
200
200
Defining the children parameter with the type ReactNode | ReactNode[]. This allows for various possibilities:
201
201
a single element, an array of elements, or null or undefined.
202
202
**/
203
- function hasActiveChild ( children : ReactNode | ReactNode [ ] ) : boolean {
203
+ function hasActiveDescendant ( children : ReactNode | ReactNode [ ] ) : boolean {
204
204
if ( Array . isArray ( children ) ) {
205
205
return children . some ( ( child ) => {
206
206
if ( ! React . isValidElement ( child ) ) {
@@ -213,9 +213,14 @@ function hasActiveChild(children: ReactNode | ReactNode[]): boolean {
213
213
const props = child . props as {
214
214
isActive ?: boolean ;
215
215
'aria-current' ?: string ;
216
+ children : ReactNode | ReactNode [ ] ;
216
217
} ;
217
218
218
- if ( props . isActive === true || props [ 'aria-current' ] ) {
219
+ if (
220
+ props . isActive === true ||
221
+ props [ 'aria-current' ] ||
222
+ ( props . children instanceof Array && hasActiveDescendant ( props . children ) )
223
+ ) {
219
224
return true ;
220
225
}
221
226
0 commit comments