@@ -369,29 +369,34 @@ const Table = <RecordType extends DefaultRecordType>(
369369 const elementTop = ( targetElement as HTMLElement ) . offsetTop ;
370370 const elementHeight = ( targetElement as HTMLElement ) . offsetHeight ;
371371 const containerHeight = container . clientHeight ;
372- const currentTop = container . scrollTop ;
373372 const elementBottom = elementTop + elementHeight ;
374- const viewportBottom = currentTop + containerHeight ;
375373 let targetTop : number ;
376374
377- if ( align === 'nearest' ) {
378- const targetWithOffset = elementTop + offset ;
379- const targetBottomWithOffset = elementBottom + offset ;
380-
381- if ( targetWithOffset < currentTop ) {
382- targetTop = targetWithOffset ;
383- } else if ( targetBottomWithOffset > viewportBottom ) {
384- targetTop = targetBottomWithOffset - containerHeight ;
385- } else {
386- targetTop = currentTop ;
375+ switch ( align ) {
376+ case 'nearest' : {
377+ const currentTop = container . scrollTop ;
378+ const viewportBottom = currentTop + containerHeight ;
379+ const targetWithOffset = elementTop + offset ;
380+ const targetBottomWithOffset = elementBottom + offset ;
381+
382+ if ( targetWithOffset < currentTop ) {
383+ targetTop = targetWithOffset ;
384+ } else if ( targetBottomWithOffset > viewportBottom ) {
385+ targetTop = targetBottomWithOffset - containerHeight ;
386+ } else {
387+ targetTop = currentTop ;
388+ }
389+ break ;
387390 }
388- } else {
389- const alignMap : Record < string , number > = {
390- start : elementTop ,
391- end : elementBottom - containerHeight ,
392- center : elementTop - ( containerHeight - elementHeight ) / 2 ,
393- } ;
394- targetTop = alignMap [ align ?? 'start' ] + offset ;
391+ case 'end' :
392+ targetTop = elementBottom - containerHeight + offset ;
393+ break ;
394+ case 'center' :
395+ targetTop = elementTop - ( containerHeight - elementHeight ) / 2 + offset ;
396+ break ;
397+ case 'start' :
398+ default :
399+ targetTop = elementTop + offset ;
395400 }
396401
397402 container . scrollTo ( { top : targetTop } ) ;
0 commit comments