@@ -74,6 +74,7 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
74
74
75
75
const inputRef = useRef < HTMLInputElement > ( null ) ;
76
76
const sidebarRef = useRef < HTMLDivElement > ( null ) ;
77
+ const toggleButtonRef = useRef < HTMLButtonElement > ( null ) ;
77
78
78
79
// Focus input when editing
79
80
useEffect ( ( ) => {
@@ -109,14 +110,19 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
109
110
if ( ! sidebarRef . current || isButtonHovered ) return ;
110
111
111
112
// Get sidebar element dimensions and position
112
- const rect = sidebarRef . current . getBoundingClientRect ( ) ;
113
+ const rect = toggleButtonRef . current ?. getBoundingClientRect ( ) ;
114
+ if ( ! rect ) return ;
113
115
const sidebarRight = rect . right ;
116
+ const sidebarYCenter = rect . top + rect . height / 2 ;
114
117
115
118
// 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
117
120
118
121
// 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 ) ;
120
126
121
127
// Only update if the value is different to avoid unnecessary re-renders
122
128
if ( isNearToggle !== isButtonVisible ) {
@@ -219,7 +225,8 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
219
225
if ( ! sidebarRef . current ) return ;
220
226
221
227
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 ;
223
230
224
231
if ( ! isNearToggle && ! isSidebarHovered ) {
225
232
setIsButtonVisible ( false ) ;
@@ -238,7 +245,9 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
238
245
if ( ! isButtonHovered ) {
239
246
const rect = sidebarRef . current ?. getBoundingClientRect ( ) ;
240
247
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
+
242
251
if ( ! isNearToggle ) {
243
252
setIsButtonVisible ( false ) ;
244
253
}
@@ -408,12 +417,13 @@ export const ChatHistoryList: React.FC<ChatHistoryListProps> = ({
408
417
409
418
{ /* Collapse toggle button */ }
410
419
< button
420
+ ref = { toggleButtonRef }
411
421
onClick = { toggleSidebar }
412
422
onMouseEnter = { handleButtonMouseEnter }
413
423
onMouseLeave = { handleButtonMouseLeave }
414
424
onFocus = { ( ) => setIsButtonVisible ( true ) }
415
425
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' } ` }
417
427
aria-label = { isCollapsed ? 'Expand sidebar' : 'Collapse sidebar' }
418
428
title = { isCollapsed ? 'Expand sidebar' : 'Collapse sidebar' }
419
429
>
0 commit comments