@@ -3,6 +3,7 @@ import type { Ref } from 'vue'
33import type { PrimitiveProps } from ' @/Primitive'
44import type { DataOrientation , Direction , StringOrNumber } from ' ../shared/types'
55import { createContext , useDirection , useForwardExpose , useId } from ' @/shared'
6+ import { useVModel } from ' @vueuse/core'
67
78export interface TabsRootContext {
89 modelValue: Ref <StringOrNumber | undefined >
@@ -14,11 +15,11 @@ export interface TabsRootContext {
1415 tabsList: Ref <HTMLElement | undefined >
1516}
1617
17- export interface TabsRootProps extends PrimitiveProps {
18+ export interface TabsRootProps < T extends StringOrNumber = StringOrNumber > extends PrimitiveProps {
1819 /**
1920 * The value of the tab that should be active when initially rendered. Use when you do not need to control the state of the tabs
2021 */
21- defaultValue? : StringOrNumber
22+ defaultValue? : T
2223 /**
2324 * The orientation the tabs are layed out.
2425 * Mainly so arrow navigation is done accordingly (left & right vs. up & down)
@@ -35,32 +36,31 @@ export interface TabsRootProps extends PrimitiveProps {
3536 */
3637 activationMode? : ' automatic' | ' manual'
3738 /** The controlled value of the tab to activate. Can be bind as `v-model`. */
38- modelValue? : StringOrNumber
39+ modelValue? : T
3940}
40- export type TabsRootEmits = {
41+ export type TabsRootEmits < T extends StringOrNumber = StringOrNumber > = {
4142 /** Event handler called when the value changes */
42- ' update:modelValue' : [payload : StringOrNumber ]
43+ ' update:modelValue' : [payload : T ]
4344}
4445
4546export const [injectTabsRootContext, provideTabsRootContext]
4647 = createContext <TabsRootContext >(' TabsRoot' )
4748 </script >
4849
49- <script setup lang="ts">
50+ <script setup lang="ts" generic = " T extends StringOrNumber = StringOrNumber " >
5051import { ref , toRefs } from ' vue'
51- import { useVModel } from ' @vueuse/core'
5252import { Primitive } from ' @/Primitive'
5353
54- const props = withDefaults (defineProps <TabsRootProps >(), {
54+ const props = withDefaults (defineProps <TabsRootProps < T > >(), {
5555 orientation: ' horizontal' ,
5656 activationMode: ' automatic' ,
5757})
58- const emits = defineEmits <TabsRootEmits >()
58+ const emits = defineEmits <TabsRootEmits < T > >()
5959const { orientation, dir : propDir } = toRefs (props )
6060const dir = useDirection (propDir )
6161useForwardExpose ()
6262
63- const modelValue = useVModel (props , ' modelValue' , emits , {
63+ const modelValue = useVModel < TabsRootProps < T >, ' modelValue ' , ' update:modelValue ' > (props , ' modelValue' , emits , {
6464 defaultValue: props .defaultValue ,
6565 passive: (props .modelValue === undefined ) as false ,
6666})
@@ -70,7 +70,7 @@ const tabsList = ref<HTMLElement>()
7070provideTabsRootContext ({
7171 modelValue ,
7272 changeModelValue : (value : StringOrNumber ) => {
73- modelValue .value = value
73+ modelValue .value = value as T
7474 },
7575 orientation ,
7676 dir ,
0 commit comments