Skip to content

Commit

Permalink
fix: tab组件滚动视图中央异常情况下报错(#663
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuo committed Sep 12, 2024
1 parent 210db8f commit 539a298
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/vantui/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function Tabs(props: TabsProps) {
getAllRect(null, `.tabs-com-index${indexRef.current} .van-tab`),
getRect(null, `.tabs-com-index${indexRef.current} .van-tabs__nav`),
]).then(([tabRects, navRect]: any) => {
if (tabRects && navRect) {
if (tabRects && tabRects.length && navRect) {
const tabRect = tabRects[index!]
const offsetLeft = tabRects
.slice(0, index)
Expand Down Expand Up @@ -311,7 +311,9 @@ export function Tabs(props: TabsProps) {
useEffect(
function () {
nextTick(() => {
scrollIntoView()
setTimeout(() => {
scrollIntoView()
}, 33)
})
if (active !== getCurrentName() && !ref.current?.swiping && !swipeable) {
setCurrentIndexByName(active)
Expand Down

0 comments on commit 539a298

Please sign in to comment.