Skip to content

Commit 80410b4

Browse files
authored
Tabs: scroll to active tab (#12948)
* Tabs: fix not scrolling to active tab * update tabs.vue
1 parent 7e29e1c commit 80410b4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/tabs/src/tab-nav.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
const navScroll = this.$refs.navScroll;
8888
const activeTabBounding = activeTab.getBoundingClientRect();
8989
const navScrollBounding = navScroll.getBoundingClientRect();
90-
const navBounding = nav.getBoundingClientRect();
90+
const maxOffset = nav.offsetWidth - navScrollBounding.width;
9191
const currentOffset = this.navOffset;
9292
let newOffset = currentOffset;
9393
@@ -97,10 +97,9 @@
9797
if (activeTabBounding.right > navScrollBounding.right) {
9898
newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
9999
}
100-
if (navBounding.right < navScrollBounding.right) {
101-
newOffset = nav.offsetWidth - navScrollBounding.width;
102-
}
103-
this.navOffset = Math.max(newOffset, 0);
100+
101+
newOffset = Math.max(newOffset, 0);
102+
this.navOffset = Math.min(newOffset, maxOffset);
104103
},
105104
update() {
106105
if (!this.$refs.nav) return;

packages/tabs/src/tabs.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
},
4646
currentName(value) {
4747
if (this.$refs.nav) {
48-
this.$nextTick(_ => {
49-
this.$refs.nav.scrollToActiveTab();
48+
this.$nextTick(() => {
49+
this.$refs.nav.$nextTick(_ => {
50+
this.$refs.nav.scrollToActiveTab();
51+
});
5052
});
5153
}
5254
}

0 commit comments

Comments
 (0)