@@ -196,10 +196,12 @@ const DocumentTabs: React.FC<DocumentTabsProps> = ({
196196 const tabStart = element . offsetLeft ;
197197 if ( tabStart < scrollLeft - 1 ) {
198198 container . scrollTo ( { left : tabStart , behavior : 'smooth' } ) ;
199+ requestAnimationFrame ( ( ) => updateScrollState ( ) ) ;
199200 return ;
200201 }
201202 }
202203 container . scrollTo ( { left : 0 , behavior : 'smooth' } ) ;
204+ requestAnimationFrame ( ( ) => updateScrollState ( ) ) ;
203205 } else {
204206 for ( let index = 0 ; index < openDocumentIds . length ; index += 1 ) {
205207 const id = openDocumentIds [ index ] ;
@@ -208,12 +210,33 @@ const DocumentTabs: React.FC<DocumentTabsProps> = ({
208210 const tabEnd = element . offsetLeft + element . offsetWidth ;
209211 if ( tabEnd > scrollLeft + clientWidth + 1 ) {
210212 container . scrollTo ( { left : tabEnd - clientWidth , behavior : 'smooth' } ) ;
213+ requestAnimationFrame ( ( ) => updateScrollState ( ) ) ;
211214 return ;
212215 }
213216 }
214217 container . scrollTo ( { left : container . scrollWidth - clientWidth , behavior : 'smooth' } ) ;
218+ requestAnimationFrame ( ( ) => updateScrollState ( ) ) ;
215219 }
216- } , [ openDocumentIds ] ) ;
220+ } , [ openDocumentIds , updateScrollState ] ) ;
221+
222+ const handleWheel = useCallback ( ( event : React . WheelEvent < HTMLDivElement > ) => {
223+ const container = scrollContainerRef . current ;
224+ if ( ! container ) return ;
225+
226+ const dominantDelta = Math . abs ( event . deltaX ) >= Math . abs ( event . deltaY )
227+ ? event . deltaX
228+ : event . shiftKey
229+ ? event . deltaY
230+ : 0 ;
231+
232+ if ( dominantDelta === 0 ) {
233+ return ;
234+ }
235+
236+ event . preventDefault ( ) ;
237+ container . scrollBy ( { left : dominantDelta } ) ;
238+ requestAnimationFrame ( ( ) => updateScrollState ( ) ) ;
239+ } , [ updateScrollState ] ) ;
217240
218241 const handleDragStart = useCallback ( ( event : React . DragEvent < HTMLDivElement > , tabId : string , index : number ) => {
219242 dragState . current = { id : tabId , index } ;
@@ -330,9 +353,10 @@ const DocumentTabs: React.FC<DocumentTabsProps> = ({
330353 < div className = "flex-1 h-full relative overflow-hidden" >
331354 < div
332355 ref = { scrollContainerRef }
333- className = "absolute inset-y-0 left-0 right-0 overflow-x-auto overflow-y- hidden scrollbar-hidden"
356+ className = "absolute inset-y-0 left-0 right-0 overflow-hidden scrollbar-hidden"
334357 onDragOver = { handleDragOver }
335358 onDrop = { handleContainerDrop }
359+ onWheel = { handleWheel }
336360 role = "tablist"
337361 >
338362 < div className = "flex items-stretch gap-1 h-full min-w-max pr-2" >
0 commit comments