Skip to content

Commit

Permalink
feat(tabs): scroll the active tab to the center position
Browse files Browse the repository at this point in the history
  • Loading branch information
Faxxicy committed Dec 1, 2024
1 parent eaaef59 commit 9a333fd
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@ export default defineComponent({
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' });
}
const scrollDistance = tabLeft - navScrollWidth / 2 + tabWidth / 2;
navScroll.value.scrollTo({ left: scrollDistance, behavior: 'smooth' });
}
};

Expand Down

0 comments on commit 9a333fd

Please sign in to comment.