Skip to content

Commit

Permalink
fix(Tabs): indicator size not updating when more tab triggers added
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Mar 8, 2024
1 parent 1cc4cd5 commit d7ce733
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/radix-vue/src/Tabs/TabsIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface IndicatorStyle {
size: number | null
position: number | null
}
const activeTab = ref<HTMLElement | null>()
const indicatorStyle = ref<IndicatorStyle>({
size: null,
position: null,
Expand All @@ -29,24 +30,24 @@ watch(() => context.modelValue.value, async (n) => {
updateIndicatorStyle()
}, { immediate: true })
useResizeObserver(context.tabsList, updateIndicatorStyle)
useResizeObserver([context.tabsList, activeTab], updateIndicatorStyle)
function updateIndicatorStyle() {
const activeTab = context.tabsList.value?.querySelector<HTMLButtonElement>('[role="tab"][data-state="active"]')
activeTab.value = context.tabsList.value?.querySelector<HTMLButtonElement>('[role="tab"][data-state="active"]')
if (!activeTab)
if (!activeTab.value)
return
if (context.orientation.value === 'horizontal') {
indicatorStyle.value = {
size: activeTab.offsetWidth,
position: activeTab.offsetLeft,
size: activeTab.value.offsetWidth,
position: activeTab.value.offsetLeft,
}
}
else {
indicatorStyle.value = {
size: activeTab.offsetHeight,
position: activeTab.offsetTop,
size: activeTab.value.offsetHeight,
position: activeTab.value.offsetTop,
}
}
}
Expand Down

0 comments on commit d7ce733

Please sign in to comment.