Skip to content

Commit

Permalink
fix(tabs): tabs auto scroll to active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyan-u committed Oct 25, 2024
1 parent 067f0c2 commit fa495b5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ export default defineComponent({

lineStyle.value = style;
}
if (navScroll.value) {
const tab = navScroll.value.querySelector<HTMLElement>(`.${activeClass}`);
if (!tab) return;
const tabLeft = tab?.offsetLeft;
const tabWidth = tab?.offsetWidth;
const navScrollScrollLeft = navScroll.value.scrollLeft;
const navScrollWidth = navScroll.value.offsetWidth;
if (tabLeft + tabWidth - navScrollScrollLeft > navScrollWidth) {
navScroll.value.scrollTo({ left: tabLeft + tabWidth - navScrollWidth, behavior: 'smooth' });
} else if (tabLeft < navScrollScrollLeft) {
navScroll.value.scrollTo({ left: tabLeft, behavior: 'smooth' });
}
}
};

onMounted(() => {
Expand Down

0 comments on commit fa495b5

Please sign in to comment.