File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22
3- import { useState } from 'react' ;
3+ import { useState , useEffect } from 'react' ;
44
55import clsx from 'clsx' ;
66
@@ -37,11 +37,17 @@ const Item = ({
3737 // Normalize the pathname to remove the trailing slash
3838 const pathname = ( usePathname ( ) ?? '' ) . replace ( / \/ $ / , '' ) ;
3939 const hasActiveChild = isActiveItem ( children , pathname ) ;
40- const [ isOpen , setIsOpen ] = useState ( ( ) => {
41- return (
42- url === pathname || hasActiveChild || ( title && depth === 1 && expandedList ?. includes ( title ) )
43- ) ;
44- } ) ;
40+ const shouldBeOpen =
41+ url === pathname || hasActiveChild || ( title && depth === 1 && expandedList ?. includes ( title ) ) ;
42+
43+ const [ isOpen , setIsOpen ] = useState ( shouldBeOpen ) ;
44+
45+ // Update open state when pathname changes (e.g., when coming from search)
46+ useEffect ( ( ) => {
47+ if ( shouldBeOpen && ! isOpen ) {
48+ setIsOpen ( true ) ;
49+ }
50+ } , [ pathname , shouldBeOpen , isOpen ] ) ;
4551
4652 const toggle = ( ) => {
4753 if ( closeMenu && url ) {
You can’t perform that action at this time.
0 commit comments