@@ -144,24 +144,40 @@ export const Tabs: FunctionComponent<Partial<TaroTabsProps>> & {
144144 const scrollIntoView = ( index : number ) => {
145145 raf ( ( ) => {
146146 Promise . all ( [
147- getRect ( `#nut-tabs-titles-${ name || uuid } .nut-tabs-list ` ) ,
147+ getRect ( `#nut-tabs-titles-${ name || uuid } ` ) ,
148148 getAllRect ( `#nut-tabs-titles-${ name || uuid } .nut-tabs-titles-item` ) ,
149149 ] ) . then ( ( [ navRect , titleRects ] : any ) => {
150150 const titleRect = titleRects [ index ]
151151 if ( ! titleRect ) return
152152
153153 let to = 0
154154 if ( direction === 'vertical' ) {
155+ const totalHeight = titleRects . reduce (
156+ ( sum : number , curr : RectItem ) => sum + curr . height ,
157+ 0
158+ )
155159 const top = titleRects
156160 . slice ( 0 , index )
157161 . reduce ( ( prev : number , curr : RectItem ) => prev + curr . height , 0 )
158- to = top - ( navRect . height - titleRect . height ) / 2
162+
163+ to = Math . min (
164+ Math . max ( 0 , top - ( navRect . height - titleRect . height ) / 2 ) ,
165+ totalHeight - navRect . height
166+ )
159167 } else {
168+ const totalWidth = titleRects . reduce (
169+ ( sum : number , curr : RectItem ) => sum + curr . width ,
170+ 0
171+ )
160172 const left = titleRects
161173 . slice ( 0 , index )
162174 . reduce ( ( prev : number , curr : RectItem ) => prev + curr . width , 0 )
163- to = left - ( navRect . width - titleRect . width ) / 2
175+ to = Math . min (
176+ Math . max ( 0 , left - ( navRect . width - titleRect . width ) / 2 ) ,
177+ totalWidth - navRect . width
178+ )
164179 }
180+
165181 scrollDirection ( to , direction )
166182
167183 nextTick ( ( ) => {
0 commit comments