From f94897cb24d87b95ba534ad2b5c6540324d62bf6 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 6 Oct 2022 16:23:05 +0800 Subject: [PATCH] fix(Tabs): incorrect nav scroll animation in some cases (#11116) * fix(Tabs): incorrect nav scroll animation in some cases * chore: fix snapshot --- .../test/__snapshots__/index.spec.ts.snap | 2 +- packages/vant/src/tabs/Tabs.tsx | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/vant/src/coupon-list/test/__snapshots__/index.spec.ts.snap b/packages/vant/src/coupon-list/test/__snapshots__/index.spec.ts.snap index 311c8b913..e29cb2abb 100644 --- a/packages/vant/src/coupon-list/test/__snapshots__/index.spec.ts.snap +++ b/packages/vant/src/coupon-list/test/__snapshots__/index.spec.ts.snap @@ -346,7 +346,7 @@ exports[`should have two "van-coupon-list__empty" classes when render coupon lis
diff --git a/packages/vant/src/tabs/Tabs.tsx b/packages/vant/src/tabs/Tabs.tsx index f32cfc06b..e8e87d63d 100644 --- a/packages/vant/src/tabs/Tabs.tsx +++ b/packages/vant/src/tabs/Tabs.tsx @@ -230,7 +230,14 @@ export default defineComponent({ const newName = getTabName(newTab, newIndex); const shouldEmitChange = state.currentIndex !== null; - state.currentIndex = newIndex; + if (state.currentIndex !== newIndex) { + state.currentIndex = newIndex; + + if (!skipScrollIntoView) { + scrollIntoView(); + } + setLine(); + } if (newName !== props.active) { emit('update:active', newName); @@ -240,11 +247,6 @@ export default defineComponent({ } } - if (!skipScrollIntoView) { - scrollIntoView(); - } - setLine(); - // scroll to correct position if (stickyFixed && !props.scrollspy) { setRootScrollTop(