@@ -144,24 +144,40 @@ export const Tabs: FunctionComponent<Partial<TaroTabsProps>> & {
144
144
const scrollIntoView = ( index : number ) => {
145
145
raf ( ( ) => {
146
146
Promise . all ( [
147
- getRect ( `#nut-tabs-titles-${ name || uuid } .nut-tabs-list ` ) ,
147
+ getRect ( `#nut-tabs-titles-${ name || uuid } ` ) ,
148
148
getAllRect ( `#nut-tabs-titles-${ name || uuid } .nut-tabs-titles-item` ) ,
149
149
] ) . then ( ( [ navRect , titleRects ] : any ) => {
150
150
const titleRect = titleRects [ index ]
151
151
if ( ! titleRect ) return
152
152
153
153
let to = 0
154
154
if ( direction === 'vertical' ) {
155
+ const totalHeight = titleRects . reduce (
156
+ ( sum : number , curr : RectItem ) => sum + curr . height ,
157
+ 0
158
+ )
155
159
const top = titleRects
156
160
. slice ( 0 , index )
157
161
. 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
+ )
159
167
} else {
168
+ const totalWidth = titleRects . reduce (
169
+ ( sum : number , curr : RectItem ) => sum + curr . width ,
170
+ 0
171
+ )
160
172
const left = titleRects
161
173
. slice ( 0 , index )
162
174
. 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
+ )
164
179
}
180
+
165
181
scrollDirection ( to , direction )
166
182
167
183
nextTick ( ( ) => {
0 commit comments