@@ -74,6 +74,7 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
7474
7575  const  inputRef  =  useRef < HTMLInputElement > ( null ) ; 
7676  const  sidebarRef  =  useRef < HTMLDivElement > ( null ) ; 
77+   const  toggleButtonRef  =  useRef < HTMLButtonElement > ( null ) ; 
7778
7879  // Focus input when editing 
7980  useEffect ( ( )  =>  { 
@@ -109,14 +110,19 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
109110      if  ( ! sidebarRef . current  ||  isButtonHovered )  return ; 
110111
111112      // Get sidebar element dimensions and position 
112-       const  rect  =  sidebarRef . current . getBoundingClientRect ( ) ; 
113+       const  rect  =  toggleButtonRef . current ?. getBoundingClientRect ( ) ; 
114+       if  ( ! rect )  return ; 
113115      const  sidebarRight  =  rect . right ; 
116+       const  sidebarYCenter  =  rect . top  +  rect . height  /  2 ; 
114117
115118      // Define the sensitivity area (how close the mouse needs to be to show the button) 
116-       const  sensitivityArea  =  40 ;  // pixels 
119+       const  sensitivityArea  =  70 ;  // pixels 
117120
118121      // Check if mouse is within the sensitivity area 
119-       const  isNearToggle  =  Math . abs ( e . clientX  -  sidebarRight )  <  sensitivityArea ; 
122+       const  isNearToggle  =  Math . abs ( e . clientX  -  sidebarRight )  <  sensitivityArea 
123+         &&  Math . abs ( e . clientY  -  sidebarYCenter )  <  sensitivityArea ; 
124+ 
125+       console . log ( 'isNearToggle' ,  isNearToggle ) ; 
120126
121127      // Only update if the value is different to avoid unnecessary re-renders 
122128      if  ( isNearToggle  !==  isButtonVisible )  { 
@@ -219,7 +225,8 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
219225    if  ( ! sidebarRef . current )  return ; 
220226
221227    const  rect  =  sidebarRef . current . getBoundingClientRect ( ) ; 
222-     const  isNearToggle  =  Math . abs ( mousePosition . x  -  rect . right )  <  40 ; 
228+     const  isNearToggle  =  Math . abs ( mousePosition . x  -  rect . right )  <  40 
229+       &&  Math . abs ( mousePosition . y  -  rect . top )  <  40 ; 
223230
224231    if  ( ! isNearToggle  &&  ! isSidebarHovered )  { 
225232      setIsButtonVisible ( false ) ; 
@@ -238,7 +245,9 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
238245    if  ( ! isButtonHovered )  { 
239246      const  rect  =  sidebarRef . current ?. getBoundingClientRect ( ) ; 
240247      if  ( rect )  { 
241-         const  isNearToggle  =  Math . abs ( mousePosition . x  -  rect . right )  <  40 ; 
248+         const  isNearToggle  =  Math . abs ( mousePosition . x  -  rect . right )  <  40 
249+           &&  Math . abs ( mousePosition . y  -  rect . top )  <  40 ; 
250+           
242251        if  ( ! isNearToggle )  { 
243252          setIsButtonVisible ( false ) ; 
244253        } 
@@ -408,12 +417,13 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
408417
409418      { /* Collapse toggle button */ } 
410419      < button  
420+         ref = { toggleButtonRef } 
411421        onClick = { toggleSidebar } 
412422        onMouseEnter = { handleButtonMouseEnter } 
413423        onMouseLeave = { handleButtonMouseLeave } 
414424        onFocus = { ( )  =>  setIsButtonVisible ( true ) } 
415425        onBlur = { ( )  =>  ! isSidebarHovered  &&  setIsButtonVisible ( false ) } 
416-         className = { `absolute z-10 flex items-center justify-center w-6 h-20 transform -translate-y-1/2 bg-gray-200 - right-6 top-1/2 hover:bg-gray-300  rounded-r-md transition-opacity duration-300 ${ isButtonVisible  ||  isButtonHovered  ? 'opacity-100'  : 'opacity-0' }  } 
426+         className = { `absolute chat-history-list-collapse-button  z-10 flex items-center justify-center w-6 h-20 transform -translate-y-1/2 - right-6 top-1/2 rounded-r-md transition-opacity duration-300 ${ isButtonVisible  ||  isButtonHovered  ? 'opacity-100'  : 'opacity-0' }  } 
417427        aria-label = { isCollapsed  ? 'Expand sidebar'  : 'Collapse sidebar' } 
418428        title = { isCollapsed  ? 'Expand sidebar'  : 'Collapse sidebar' } 
419429      > 
0 commit comments