Skip to content

Commit

Permalink
fix(Tabs): add ResizeObserver for Indicator (#602) (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Ellis authored Jan 16, 2024
1 parent 12b3d6b commit 9627e2d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/radix-vue/src/Tabs/TabsIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TabsIndicatorProps extends PrimitiveProps {

<script setup lang="ts">
import { Primitive } from '@/Primitive'
import { useResizeObserver } from '@vueuse/core'
const props = defineProps<TabsIndicatorProps>()
const context = injectTabsRootContext()
Expand All @@ -24,6 +25,12 @@ const indicatorStyle = ref<IndicatorStyle>({
watch(() => context.modelValue.value, async (n) => {
await nextTick()
updateIndicatorStyle()
}, { immediate: true })
useResizeObserver(context.tabsList, updateIndicatorStyle)
function updateIndicatorStyle() {
const activeTab = context.tabsList.value?.querySelector<HTMLButtonElement>('[role="tab"][data-state="active"]')
if (!activeTab)
Expand All @@ -41,7 +48,7 @@ watch(() => context.modelValue.value, async (n) => {
position: activeTab.offsetTop,
}
}
}, { immediate: true })
}
</script>

<template>
Expand Down

0 comments on commit 9627e2d

Please sign in to comment.