@@ -3,6 +3,7 @@ import type { Ref } from 'vue'
3
3
import type { PrimitiveProps } from ' @/Primitive'
4
4
import type { DataOrientation , Direction , StringOrNumber } from ' ../shared/types'
5
5
import { createContext , useDirection , useForwardExpose , useId } from ' @/shared'
6
+ import { useVModel } from ' @vueuse/core'
6
7
7
8
export interface TabsRootContext {
8
9
modelValue: Ref <StringOrNumber | undefined >
@@ -14,11 +15,11 @@ export interface TabsRootContext {
14
15
tabsList: Ref <HTMLElement | undefined >
15
16
}
16
17
17
- export interface TabsRootProps extends PrimitiveProps {
18
+ export interface TabsRootProps < T extends StringOrNumber = StringOrNumber > extends PrimitiveProps {
18
19
/**
19
20
* 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
20
21
*/
21
- defaultValue? : StringOrNumber
22
+ defaultValue? : T
22
23
/**
23
24
* The orientation the tabs are layed out.
24
25
* Mainly so arrow navigation is done accordingly (left & right vs. up & down)
@@ -35,32 +36,31 @@ export interface TabsRootProps extends PrimitiveProps {
35
36
*/
36
37
activationMode? : ' automatic' | ' manual'
37
38
/** The controlled value of the tab to activate. Can be bind as `v-model`. */
38
- modelValue? : StringOrNumber
39
+ modelValue? : T
39
40
}
40
- export type TabsRootEmits = {
41
+ export type TabsRootEmits < T extends StringOrNumber = StringOrNumber > = {
41
42
/** Event handler called when the value changes */
42
- ' update:modelValue' : [payload : StringOrNumber ]
43
+ ' update:modelValue' : [payload : T ]
43
44
}
44
45
45
46
export const [injectTabsRootContext, provideTabsRootContext]
46
47
= createContext <TabsRootContext >(' TabsRoot' )
47
48
</script >
48
49
49
- <script setup lang="ts">
50
+ <script setup lang="ts" generic = " T extends StringOrNumber = StringOrNumber " >
50
51
import { ref , toRefs } from ' vue'
51
- import { useVModel } from ' @vueuse/core'
52
52
import { Primitive } from ' @/Primitive'
53
53
54
- const props = withDefaults (defineProps <TabsRootProps >(), {
54
+ const props = withDefaults (defineProps <TabsRootProps < T > >(), {
55
55
orientation: ' horizontal' ,
56
56
activationMode: ' automatic' ,
57
57
})
58
- const emits = defineEmits <TabsRootEmits >()
58
+ const emits = defineEmits <TabsRootEmits < T > >()
59
59
const { orientation, dir : propDir } = toRefs (props )
60
60
const dir = useDirection (propDir )
61
61
useForwardExpose ()
62
62
63
- const modelValue = useVModel (props , ' modelValue' , emits , {
63
+ const modelValue = useVModel < TabsRootProps < T >, ' modelValue ' , ' update:modelValue ' > (props , ' modelValue' , emits , {
64
64
defaultValue: props .defaultValue ,
65
65
passive: (props .modelValue === undefined ) as false ,
66
66
})
@@ -70,7 +70,7 @@ const tabsList = ref<HTMLElement>()
70
70
provideTabsRootContext ({
71
71
modelValue ,
72
72
changeModelValue : (value : StringOrNumber ) => {
73
- modelValue .value = value
73
+ modelValue .value = value as T
74
74
},
75
75
orientation ,
76
76
dir ,
0 commit comments